*******************************************************************************
*MERGE ALL THE ORIGINAL DATA FILES:
*Social inequalities cumulative file: ZA5890_v1-0-0.dta
*Social inequalities add-on file: ZA5891_v1-1-0 (ADD-ON).dta
*DATASET_2002
*DATASET_2003
*DATASET_2004
*DATASET_2005
*DATASET_2006
*DATASET_2007
*DATASET_2008
*DATASET_2010
*DATASET_2011
*DATASET_2012
*DATASET_2013
*DATASET_2014
*DATASET_2015
*DATASET_2016
*DATASET_2017
*******************************************************************************

*set the global for data folder (ISSP)
global path ....
*******************************************************************************
*PREPARE CUMULATIVE DATASETS social inequalities 1987, 1992, 1999, 2009
*******************************************************************************

use "$path\ZA5890_v1-0-0.dta", clear
save "$path\DATASET_inequalities1987-2009_1.dta", replace


*elaborate the original addon file
use "$path\ZA5891_v1-1-0 (ADD-ON).dta", clear

*rename V8-V37 in order to be able to combine add-on dataset with cumulative dataset
rename	V8	VAD8
rename	V9	VAD9
rename	V10	VAD10
rename	V11	VAD11
rename	V12	VAD12
rename	V13	VAD13
rename	V14	VAD14
rename	V15	VAD15
rename	V16	VAD16
rename	V17	VAD17
rename	V18	VAD18
rename	V19	VAD19
rename	V20	VAD20
rename	V21	VAD21
rename	V22	VAD22
rename	V23	VAD23
rename	V24	VAD24
rename	V25	VAD25
rename	V26	VAD26
rename	V27	VAD27
rename	V28	VAD28
rename	V29	VAD29
rename	V30	VAD30
rename	V31	VAD31
rename	V32	VAD32
rename	V33	VAD33
rename	V34	VAD34
rename	V35	VAD35
rename	V36	VAD36
rename	V37	VAD37

save "$path\DATASET_addon1987-2009.dta", replace

***MERGE DATASET with ADD ON dataset
use "$path\DATASET_inequalities1987-2009_1.dta", clear
merge 1:1 V3 V7 using "$path\DATASET_addon1987-2009.dta"
save "$path\DATASET_inequalities1987-2009.dta", replace


***Change variable names
rename V1 study_number
rename V2 archive_version
rename V3 respondent_number
rename V4 year
rename V5 country
rename V6 country_sample
rename V7 country_sample_year

***upper case for all the original variables
rename _all, upper 

***prepare country variable and labels for merging
recode COUNTRY (826=82601)

label define V5 36 "AU-Australia" 40 "AT-Austria" 100 "BG-Bulgaria" 124 "CA-Canada" 152 "CL-Chile" 196 "CY-Cyprus" 203 "CZ-Czech Republic" 250 "FR-France" 276 "DE-Germany" 348 "HU-Hungary" 376 "IL-Israel" 380 "IT-Italy" 392 "JP-Japan"428 "LV-Latvia" 554 "NZ-New Zealand" 578 "NO-Norway" 608 "PH-Philippines" 616"PL-Poland" 620 "PT-Portugal" 643 "RU-Russia" 703 "SK-Slovak Republic" 705 "SI-Slovenia" 724 "ES-Spain" 752 "SE-Sweden" 756 "CH-Switzerland" 82601 "United Kingdom (Great Britain only)" 840 "US-United States" 826 "UK-United Kingdom", replace
label define V5 36 "AU-Australia" 40 "AT-Austria" 100 "BG-Bulgaria" 124 "CA-Canada" 152 "CL-Chile" 196 "CY-Cyprus" 203 "CZ-Czech Republic" 250 "FR-France" 276 "DE-Germany" 348 "HU-Hungary" 376 "IL-Israel" 380 "IT-Italy" 392 "JP-Japan"428 "LV-Latvia" 554 "NZ-New Zealand" 578 "NO-Norway" 608 "PH-Philippines" 616"PL-Poland" 620 "PT-Portugal" 643 "RU-Russia" 703 "SK-Slovak Republic" 705 "SI-Slovenia" 724 "ES-Spain" 752 "SE-Sweden" 756 "CH-Switzerland" 826 "UK-UnitedKingdom" 840 "US-United States" 82601 "United Kingdom (Great Britain only)" 528 "NL-Netherlands" 208 "DK-Denmark" 56 "BE-Belgium/Flanders" 76 "BR-Brazil" 246 "FI-Finland" 484 "MX-Mexico" 158 "TW-Taiwan" 862 "VE-Venezuela" 710 "ZA-SouthAfrica" 372 "IE-Ireland" 410 "KR-South Korea" 858 "UY-Uruguay", replace


***prepare value labels
capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'123"
la val `var' `var'123
} 

la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'

capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'"
la val `var' `var'
}

la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'

save "$path\DATASET_inequalities1987-2009.dta", replace


*******************************************************************************
*PREPARE ANNUAL DATASETS 2002-2017
*******************************************************************************

*2002
use "$path\DATASET_2002.dta", clear
gen year=2002

recode COUNTRY (1=36) (2=27601) (3=27602) (4=82601) (5=82602) (6=840) (7=40) (8=348) (10=372) (11=528) (12=578) (13=752) (14=203) (15=705) (16=616) (17=100) (18=643) (19=554) (21=608) (22=376) (24=392) (25=724) (26=428) (27=703) (28=250) (29=196) (30=620) (31=152) (32=208) (33=756) (34=56) (35=76) (37=246) (38=484) (39=158)

rename  COUNTRY country_sample
gen COUNTRY=country_sample
recode COUNTRY (27601=276) (27602=276) 

rename v1 V1
rename v2 V2
rename v3 V3
rename V1 study_number
rename V2 archive_version
rename V3 respondent_number

drop v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 v17 v18 v19 v20 v21 v22 v23 v24 v25 v26 v27 v28 v29 v30 v31 v32 v33 v34 v35 v36 v37 v38 v39 v40 v41 v42 v43 v44 v45 v46 v47 v48 v49 v50 v51 v52 v53 v54 v55 v56 v57 v58 v59 v60 v61 v62 v63 v64 v65 v66 v67 v68 v69 v70 v71

rename v200 SEX
rename v201 AGE
rename v202 MARITAL
rename v203 COHAB 
rename v204 EDUCYRS
rename v205 DEGREE
rename v239 WRKST
rename v240 WRKHRS
rename v241 ISCO88
rename v242 WRKTYPE
rename v243 NEMPLOY
rename v244 WRKSUP
rename v245 UNION
rename v246 SPWRKST
rename v247 SPISCO88
rename v248 SPWRKTYP
rename v249 RINC
*(=earnings)
rename v250 INC
*(=family income)
rename v251 HOMPOP
rename v252 HHCYCLE
rename v253 PRTY_LR
rename v287 VOTE_LE
rename v288 RELIG
rename v290 ATTEND
rename v289 RELIGGRP
rename v291 TOPBOT

rename v358 UBRURAL
rename v359 ETHNIC
rename v360 MODE
rename v361 WEIGHT

rename	v292	AT_REG
rename 	v293	AU_REG
rename	v294	BG_REG
rename 	v295	BR_REG
rename	v296	CH_REG
rename 	v297	CY_REG
rename	v298	CZ_REG
rename 	v299	DE_REG
rename	v300	DK_REG
rename 	v301	ES_REG
rename	v302	FR_REG
rename 	v303	BE_REG
rename	v304	GB_REG
rename 	v305	HU_REG
rename	v306	IL_REG
rename 	v307	IE_REG
rename	v308	JP_REG
rename 	v309	LV_REG
rename	v310	MX_REG
rename 	v311	NO_REG
rename	v312	NL_REG
rename 	v313	NZ_REG
rename	v314	PT_REG
rename 	v315	PL_REG
rename	v316	CL_REG
rename 	v317	PH_REG
rename	v318	RU_REG
rename 	v319	SE_REG
rename	v320	FI_REG
rename 	v321	SK_REG
rename	v322	SI_REG
rename 	v323	TW_REG
rename	v324	US_REG
rename 	v325	AT_SIZE
rename	v326	AU_SIZE
rename 	v327	BG_SIZE
rename	v328	BR_SIZE
rename 	v329	CH_SIZE
rename	v330	CY_SIZE
rename 	v331	CZ_SIZE
rename	v332	DE_SIZE
rename 	v333	DK_SIZE
rename	v334	ES_SIZE
rename 	v335	FR_SIZE
rename	v336	BE_SIZE
rename 	v337	GB_SIZE
rename	v338	HU_SIZE
rename 	v339	IL_SIZE
rename	v340	IE_SIZE
rename 	v341	JP_SIZE
rename	v342	LV_SIZE
rename 	v343	MX_SIZE
rename	v344	NO_SIZE
rename 	v345	NL_SIZE
rename	v346	NZ_SIZE
rename 	v347	PT_SIZE
rename	v348	PL_SIZE
rename 	v349	CL_SIZE
rename	v350	PH_SIZE
rename 	v351	RU_SIZE
rename	v352	SE_SIZE
rename 	v353	FI_SIZE
rename	v354	SK_SIZE
rename 	v355	SI_SIZE
rename	v356	TW_SIZE
rename 	v357	US_SIZE



rename	v254	AT_PRT02
rename	v255	AU_prt02
rename	v256	BG_PRT02
rename	v257	BR_PRT02
rename	v258	CH_PRT02
rename	v259	CY_PRT02
rename	v260	CZ_PRT02
rename	v261	DE_PRT02
rename	v262	DK_PRT02
rename	v263	ES_PRT02
rename	v264	FR_PRT02
rename	v265	BE_PRT02
rename	v266	GB_PRT02
rename	v267	HU_PRT02
rename	v268	IL_PRT02
rename	v269	IE_PRT02
rename	v270	JP_PRT02
rename	v271	LV_PRT02
rename	v272	MX_PRT02
rename	v273	NO_PRT02
rename	v274	NL_PRT02
rename	v275	NZ_PRT02
rename	v276	PT_PRT02
rename	v277	PL_PRT02
rename	v278	CL_PRT02
rename	v279	PH_PRT02
rename	v280	RU_PRT02
rename	v281	SE_PRT02
rename	v282	FI_PRT02
rename	v283	SK_PRT02
rename	v284	SI_PRT02
rename	v285	TW_PRT02
rename	v286	US_PRT02

 	forvalues i=206(1)238{
		   local label : var label  v`i'
 di "`label'"
          local first = strpos(`"`label'"', "(")  + 1
		  di "`first'"
          local second = strpos(`"`label'"', "_") +1 
		  di "`second'"
          local third = strpos(`"`label'"', ")")  
		  di "`third'"
          local newlabel1 = substr(`"`label'"', `second' ,  `third'-`second' )
		  di  "`newlabel1'"
		  local newlabel2 = substr(`"`label'"', `first' ,  `second'-`first' )
		  di  "`newlabel2'"
clonevar "`newlabel2'_`newlabel1'"= v`i'
 }
 
 rename *_DEGR *_DEGR02

  drop v206 v207 v208 v209 v210 v211 v212 v213 v214 v215 v216 v217 v218 v219 v220 v221 v222 v223 v224 v225 v226 v227 v228 v229 v230 v231 v232 v233 v234 v235 v236 v237 v238
 
 foreach var of varlist study_number archive_version respondent_number country_sample C_ALPHAN SEX AGE MARITAL COHAB EDUCYRS DEGREE WRKST WRKHRS ISCO88 WRKTYPE NEMPLOY WRKSUP UNION SPWRKST SPISCO88 SPWRKTYP RINC INC HOMPOP HHCYCLE PRTY_LR AT_PRT02 AU_prt02 BG_PRT02 BR_PRT02 CH_PRT02 CY_PRT02 CZ_PRT02 DE_PRT02 DK_PRT02 ES_PRT02 FR_PRT02 BE_PRT02 GB_PRT02 HU_PRT02 IL_PRT02 IE_PRT02 JP_PRT02 LV_PRT02 MX_PRT02 NO_PRT02 NL_PRT02 NZ_PRT02 PT_PRT02 PL_PRT02 CL_PRT02 PH_PRT02 RU_PRT02 SE_PRT02 FI_PRT02 SK_PRT02 SI_PRT02 TW_PRT02 US_PRT02 VOTE_LE RELIG RELIGGRP ATTEND TOPBOT AT_REG AU_REG BG_REG BR_REG CH_REG CY_REG CZ_REG DE_REG DK_REG ES_REG FR_REG BE_REG GB_REG HU_REG IL_REG IE_REG JP_REG LV_REG MX_REG NO_REG NL_REG NZ_REG PT_REG PL_REG CL_REG PH_REG RU_REG SE_REG FI_REG SK_REG SI_REG TW_REG US_REG AT_SIZE AU_SIZE BG_SIZE BR_SIZE CH_SIZE CY_SIZE CZ_SIZE DE_SIZE DK_SIZE ES_SIZE FR_SIZE BE_SIZE GB_SIZE HU_SIZE IL_SIZE IE_SIZE JP_SIZE LV_SIZE MX_SIZE NO_SIZE NL_SIZE NZ_SIZE PT_SIZE PL_SIZE CL_SIZE PH_SIZE RU_SIZE SE_SIZE FI_SIZE SK_SIZE SI_SIZE TW_SIZE US_SIZE UBRURAL ETHNIC MODE WEIGHT year AT__DEGR02 AU__DEGR02 BG__DEGR02 BR__DEGR02 CH__DEGR02 CY__DEGR02 CZ__DEGR02 DE__DEGR02 DK__DEGR02 ES__DEGR02 FR__DEGR02 BE__DEGR02 GB__DEGR02 HU__DEGR02 IL__DEGR02 IE__DEGR02 JP__DEGR02 LV__DEGR02 MX__DEGR02 NO__DEGR02 NL__DEGR02 NZ__DEGR02 PT__DEGR02 PL__DEGR02 CL__DEGR02 PH__DEGR02 RU__DEGR02 SE__DEGR02 FI__DEGR02 SK__DEGR02 SI__DEGR02 TW__DEGR02 US__DEGR02 _all {
rename _all, upper 
}
 
*CHANGE VALUE LABELS NAMES
capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'"
la val `var' `var'
}

save "$path\DATASET_2002_1.dta", replace


********************************************************************************
*2003
********************************************************************************

use "$path\DATASET_2003.dta", clear

gen year=2003

rename v1 study_number
rename V2 archive_version
rename V3 respondent_number

recode COUNTRY (1=36) (2=27601) (3=27602) (4=82601) (5=82602) (6=840) (7=40) (8=348) (10=372) (11=528) (12=578) (13=752) (14=203) (15=705) (16=616) (17=100) (18=643) (19=554) (21=608) (24=392) (25=724) (26=428) (27=703) (28=250) (29=196) (30=620) (31=152) (32=208) (33=756) (34=56) (35=76) (37=246) (38=484) (39=158) (20=124) (23=37602) (22=37601) (36=862) (40=710) (41=158) (42=410) (43=858)
rename COUNTRY COUNTRY_SAMPLE
gen COUNTRY=COUNTRY_SAMPLE
recode COUNTRY (27601=276) (27602=276) (37601=376) (37602=376)

drop v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 v17 v18 v19 v20 v21 v22 v23 v24 v25 v26 v27 v28 v29 v30 v31 v32 v33 v34 v35 v36 v37 v38 v39 v40 v41 v42 v43 v44 v45 v46 v47 v48 v49 v50 v51 v52 v53 v54 v55 v56 v57 v58 v59 v60 v61 v62 v63 v64 v65 v66 v67 v68 v69 v70_1 v70_2 v71 v72 v73 v74

drop isco88_1 spis88_1

foreach var of varlist sex age marital cohab educyrs degree wrkst wrkhrs isco88 wrktype nemploy wrksup union spwrkst spisco88 spwrktyp rincome income hompop hhcycle at_degr au_degr bg_degr ca_degr ch_degr cz_degr de_degr dk_degr es_degr fr_degr gb_degr hu_degr il_degr ie_degr jp_degr kr_degr lv_degr nl_degr no_degr nz_degr pl_degr pt_degr cl_degr ph_degr ru_degr se_degr fi_degr sk_degr si_degr tw_degr us_degr uy_degr ve_degr za_degr party_lr at_prty au_prty bg_prty ca_prty ch_prty cz_prty de_prty dk_prty es_prty fr_prty gb_prty hu_prty il_prty ie_prty jp_prty kr_prty lv_prty nl_prty no_prty nz_prty pl_prty pt_prty cl_prty ph_prty ru_prty se_prty fi_prty sk_prty si_prty tw_prty us_prty uy_prty ve_prty za_prty vote_le relig religgrp attend topbot at_reg au_reg bg_reg ca_reg ch_reg cz_reg de_reg dk_reg es_reg fr_reg gb_reg hu_reg il_reg ie_reg jp_reg kr_reg lv_reg nl_reg no_reg nz_reg pl_reg pt_reg cl_reg ph_reg ru_reg se_reg fi_reg sk_reg si_reg tw_reg us_reg uy_reg ve_reg za_reg at_size au_size ca_size ch_size cl_size cz_size de_size dk_size es_size fr_size gb_size hu_size il_size ie_size jp_size kr_size lv_size nl_size no_size bg_size nz_size pl_size pt_size ph_size ru_size se_size fi_size sk_size si_size tw_size us_size uy_size ve_size za_size urbrural ethnic mode weight _all {
rename _all, upper 
}
foreach x of varlist (AT_PRTY AU_PRTY BG_PRTY CA_PRTY CH_PRTY CZ_PRTY DE_PRTY DK_PRTY ES_PRTY FR_PRTY GB_PRTY HU_PRTY IL_PRTY IE_PRTY JP_PRTY KR_PRTY LV_PRTY NL_PRTY NO_PRTY NZ_PRTY PL_PRTY PT_PRTY CL_PRTY PH_PRTY RU_PRTY SE_PRTY FI_PRTY SK_PRTY SI_PRTY TW_PRTY US_PRTY UY_PRTY VE_PRTY ZA_PRTY KR_REG UY_REG VE_REG ZA_REG CA_SIZE KR_SIZE UY_SIZE VE_SIZE ZA_SIZE) {
rename `x' `x'03
} 

 
 rename *_DEGR *_DEGR03

 
*CHANGE VALUE LABELS NAMES
capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'123"
la val `var' `var'123
} 


la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'


capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'"
la val `var' `var'
}

save "$path\DATASET_2003_1.dta", replace


********************************************************************************
*2004
********************************************************************************

use "$path\DATASET_2004.dta", clear

rename v1 study_number
rename v2 archive_version
rename v3 respondent_number
rename COUNTRY country_sample
gen year=2004
drop V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 V21 V22 V23 V24 V25 V26 V27 V28 V29 V30 V31 V32 V33 V34 V35 V36 V37 V38 V39 V40 V41 V42 V43 V44 V45 V46 V47 V48 V49 V50 V51 V52 V53 V54 V55 V56 V57 V58 V59 V60 V61 V62 V63 V64 V65 V66 V67 V68 V69
 rename v200 SEX
 
	forvalues i=201(1)205{
		   local label : var label  v`i'
 di "`label'"
          local first = strpos(`"`label'"', "(") + 1
		  di "`first'"
          local second = strpos(`"`label'"', ")")  
		  di "`second'"

          local newlabel = substr(`"`label'"', `first', `second' - `first')
		  di "`newlabel'"
clonevar "`newlabel'"= v`i'	  
 }
 
 	forvalues i=206(1)243{
		   local label : var label  v`i'
 di "`label'"
          local first = strpos(`"`label'"', "(")  + 1
		  di "`first'"
          local second = strpos(`"`label'"', "_") +1 
		  di "`second'"
          local third = strpos(`"`label'"', ")")  
		  di "`third'"
          local newlabel1 = substr(`"`label'"', `second' ,  `third'-`second' )
		  di  "`newlabel1'"
		  local newlabel2 = substr(`"`label'"', `first' ,  `second'-`first' )
		  di  "`newlabel2'"
clonevar "`newlabel2'_`newlabel1'"= v`i'
 }
 
 rename *_DEGR *_DEGR04
 
 	forvalues i=244(1)257{
		   local label : var label  v`i'
 di "`label'"
          local first = strpos(`"`label'"', "(") + 1
		  di "`first'"
          local second = strpos(`"`label'"', ")")  
		  di "`second'"

          local newlabel = substr(`"`label'"', `first', `second' - `first')
		  di "`newlabel'"
clonevar "`newlabel'"= v`i'	  
 }
 
 clonevar PRTY_LR = v258 
 
 
  	forvalues i=259(1)297{
		   local label : var label  v`i'
 di "`label'"
          local first = strpos(`"`label'"', "(")  + 1
		  di "`first'"
          local second = strpos(`"`label'"', "_") +1 
		  di "`second'"
          local third = strpos(`"`label'"', ")")  
		  di "`third'"
          local newlabel1 = substr(`"`label'"', `second' ,  `third'-`second' )
		  di  "`newlabel1'"
		  local newlabel2 = substr(`"`label'"', `first' ,  `second'-`first' )
		  di  "`newlabel2'"
clonevar "`newlabel2'_`newlabel1'"= v`i'
 }
  rename v298 RELIG
  rename v299 RELIGGRP

 	forvalues i=300(1)301{
		   local label : var label  v`i'
 di "`label'"
          local first = strpos(`"`label'"', "(") + 1
		  di "`first'"
          local second = strpos(`"`label'"', ")")  
		  di "`second'"

          local newlabel = substr(`"`label'"', `first', `second' - `first')
		  di "`newlabel'"
clonevar "`newlabel'"= v`i'	  
 }
 

 forvalues i=302(1)377{
		   local label : var label  v`i'
			di "`label'"
          local first = strpos(`"`label'"', "(")  + 1
		  di "`first'"
          local second = strpos(`"`label'"', "_") +1 
		  di "`second'"
          local third = strpos(`"`label'"', ")")  
		  di "`third'"
          local newlabel1 = substr(`"`label'"', `second' ,  `third'-`second' )
		  di  "`newlabel1'"
		  local newlabel2 = substr(`"`label'"', `first' ,  `second'-`first' )
		  di  "`newlabel2'"
clonevar "`newlabel2'_`newlabel1'"= v`i'  
 }
 
 
  	forvalues i=378(1)381{
		   local label : var label  v`i'
 di "`label'"
          local first = strpos(`"`label'"', "(") + 1
		  di "`first'"
          local second = strpos(`"`label'"', ")")  
		  di "`second'"

          local newlabel = substr(`"`label'"', `first', `second' - `first')
		  di "`newlabel'"
clonevar "`newlabel'"= v`i'	  
 }
 
drop v201 v202 v203 v204 v205 v206 v207 v208 v209 v210 v211 v212 v213 v214 v215 v216 v217 v218 v219 v220 v221 v222 v223 v224 v225 v226 v227 v228 v229 v230 v231 v232 v233 v234 v235 v236 v237 v238 v239 v240 v241 v242 v243 v244 v245 v246 v247 v248 v249 v250 v251 v252 v253 v254 v255 v256 v257 v258 v259 v260 v261 v262 v263 v264 v265 v266 v267 v268 v269 v270 v271 v272 v273 v274 v275 v276 v277 v278 v279 v280 v281 v282 v283 v284 v285 v286 v287 v288 v289 v290 v291 v292 v293 v294 v295 v296 v297 RELIG RELIGGRP v300 v301 v302 v303 v304 v305 v306 v307 v308 v309 v310 v311 v312 v313 v314 v315 v316 v317 v318 v319 v320 v321 v322 v323 v324 v325 v326 v327 v328 v329 v330 v331 v332 v333 v334 v335 v336 v337 v338 v339 v340 v341 v342 v343 v344 v345 v346 v347 v348 v349 v350 v351 v352 v353 v354 v355 v356 v357 v358 v359 v360 v361 v362 v363 v364 v365 v366 v367 v368 v369 v370 v371 v372 v373 v374 v375 v376 v377 v378 v379 v380 v381
 
foreach x of varlist AT__PRTY AU__PRTY BG__PRTY BR__PRTY CA__PRTY CH__PRTY CL__PRTY CY__PRTY CZ__PRTY DE__PRTY DK__PRTY ES__PRTY FI__PRTY BE__PRTY FR__PRTY GB__PRTY HU__PRTY IE__PRTY IL__PRTY JP__PRTY KR__PRTY LV__PRTY MX__PRTY NL__PRTY NO__PRTY NZ__PRTY PH__PRTY PL__PRTY PT__PRTY RU__PRTY SE__PRTY SI__PRTY SK__PRTY TW__PRTY US__PRTY UY__PRTY VE__PRTY ZA__PRTY{
rename `x' `x'04
} 


*tutto maiuscolo
rename study_number archive_version respondent_number country_sample C_ALPHAN SEX year AGE MARITAL COHAB EDUCYRS DEGREE AT__DEGR04 AU__DEGR04 BG__DEGR04 BR__DEGR04 CA__DEGR04 CH__DEGR04 CL__DEGR04 CY__DEGR04 CZ__DEGR04 DE__DEGR04 DK__DEGR04 ES__DEGR04 FI__DEGR04 BE__DEGR04 FR__DEGR04 GB__DEGR04 HU__DEGR04 IE__DEGR04 IL__DEGR04 JP__DEGR04 KR__DEGR04 LV__DEGR04 MX__DEGR04 NL__DEGR04 NO__DEGR04 NZ__DEGR04 PH__DEGR04 PL__DEGR04 PT__DEGR04 RU__DEGR04 SE__DEGR04 SI__DEGR04 SK__DEGR04 TW__DEGR04 US__DEGR04 UY__DEGR04 VE__DEGR04 ZA__DEGR04 WRKST WRKHRS ISCO88 WRKTYPE NEMPLOY WRKSUP UNION SPWRKST SPISCO88 SPWRKTYP RINC INC HOMPOP HHCYCLE PRTY_LR AT__PRTY04 AU__PRTY04 BG__PRTY04 BR__PRTY04 CA__PRTY04 CH__PRTY04 CL__PRTY04 CY__PRTY04 CZ__PRTY04 DE__PRTY04 DK__PRTY04 ES__PRTY04 FI__PRTY04 BE__PRTY04 FR__PRTY04 GB__PRTY04 HU__PRTY04 IE__PRTY04 IL__PRTY04 JP__PRTY04 KR__PRTY04 LV__PRTY04 MX__PRTY04 NL__PRTY04 NO__PRTY04 NZ__PRTY04 PH__PRTY04 PL__PRTY04 PT__PRTY04 RU__PRTY04 SE__PRTY04 SI__PRTY04 SK__PRTY04 TW__PRTY04 US__PRTY04 UY__PRTY04 VE__PRTY04 ZA__PRTY04 VOTE__LE ATTEND TOPBOT AT__REG AU__REG BG__REG BR__REG CA__REG CH__REG CL__REG CY__REG CZ__REG DE__REG DK__REG ES__REG FI__REG BE__REG FR__REG GB__REG HU__REG IE__REG IL__REG JP__REG KR__REG LV__REG MX__REG NL__REG NO__REG NZ__REG PH__REG PL__REG PT__REG RU__REG SE__REG SI__REG SK__REG TW__REG US__REG UY__REG VE__REG ZA__REG AT__SIZE AU__SIZE BG__SIZE BR__SIZE CA__SIZE CH__SIZE CL__SIZE CY__SIZE CZ__SIZE DE__SIZE DK__SIZE ES__SIZE FI__SIZE BE__SIZE FR__SIZE GB__SIZE HU__SIZE IE__SIZE IL__SIZE JP__SIZE KR__SIZE LV__SIZE MX__SIZE NL__SIZE NO__SIZE NZ__SIZE PH__SIZE PL__SIZE PT__SIZE RU__SIZE SE__SIZE SI__SIZE SK__SIZE TW__SIZE US__SIZE UY__SIZE VE__SIZE ZA__SIZE URBRURAL ETHNIC MODE WEIGHT, upper


*CHANGE VALUE LABELS NAMES
capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'123"
la val `var' `var'123
} 


la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'


capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'"
la val `var' `var'
}

recode COUNTRY_SAMPLE (36=862) (1=36) (2=27601) (3=27602) (4=82601) (6=840) (40=710) (7=40) (8=348) (10=372) (11=528) (12=578) (13=752) (14=203) (15=705) (16=616) (17=100) (18=643) (19=554) (20=124) (21=608) (22=376) (24=392) (25=724) (26=428) (27=703) (28=250) (29=196) (30=620) (31=152) (32=208) (33=756) (34=56) (35=76) (37=246) (38=484) (39=158) (41=410) (42=858)

gen COUNTRY=COUNTRY_SAMPLE
recode COUNTRY (27601=276) (27602=276) 

save "$path\DATASET_2004_1.dta", replace


********************************************************************************
*2005
********************************************************************************

use "$path\DATASET_2005.dta", clear

rename V1 study_number
rename V2 archive_version
rename V3 respondent_number
rename COUNTRY country_sample
gen year=2005
drop V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 V21 V22 V23 V23_CZ V24 V25 V26 V27 V28 V29 V30 V31 V32 V33 V34 V35 V36 V37 V38 V39 V40 V41 V42 V43 V44 V45 V46 V47 V48 V49 V50 V51 V52 V53 V54 V55 V56 V57 V58 V59 V60 V61 V62 V63 V64 V65 V66 V67 V68 V69 V70 V71 V72 V73 V74 V75 V76 V77 V78 V79 V80 V81 V82 V83 V84 V85 V86 V87
 


foreach x of varlist AU_DEGR BG_DEGR CA_DEGR CH_DEGR CY_DEGR CZ_DEGR DE_DEGR DK_DEGR DO_DEGR ES_DEGR FI_DEGR BE_DEGR FR_DEGR GB_DEGR HU_DEGR IE_DEGR IL_DEGR JP_DEGR KR_DEGR LV_DEGR MX_DEGR NL_DEGR NO_DEGR NZ_DEGR PH_DEGR PT_DEGR RU_DEGR SE_DEGR SI_DEGR TW_DEGR US_DEGR ZA_DEGR AU_PRTY BG_PRTY CA_PRTY CH_PRTY CY_PRTY CZ_PRTY DE_PRTY DK_PRTY DO_PRTY ES_PRTY FI_PRTY BE_PRTY FR_PRTY GB_PRTY HU_PRTY IE_PRTY IL_PRTY JP_PRTY KR_PRTY LV_PRTY MX_PRTY NL_PRTY NO_PRTY NZ_PRTY PH_PRTY PT_PRTY RU_PRTY SE_PRTY SI_PRTY TW_PRTY US_PRTY ZA_PRTY{
rename `x' `x'05
} 


rename _all, upper


*change value labels
capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'123"
la val `var' `var'123
} 


la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'


capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'"
la val `var' `var'
}

la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'

save "$path\DATASET_2005_1.dta", replace


********************************************************************************
*2006
********************************************************************************

use "$path\DATASET_2006.dta"

rename V1 study_number
rename version archive_version
rename V2 respondent_number
rename V3 country_sample
rename V3a country
gen year=2006

drop V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 V21 V22 V23 V24 V25 V26 V27 V28 V29 V30 V31 V32 V33 V34 V35 V36 V37 V38 V39 V40 V41 V42 V43 V44 V45 V46 V47 V48 V49 V50 V51 V52 V53 V54 V55 V56 V57 V58 V59 V60 V61 V62 V63

foreach x of varlist AU_DEGR CA_DEGR CH_DEGR CL_DEGR CZ_DEGR DE_DEGR DK_DEGR DO_DEGR ES_DEGR FI_DEGR FR_DEGR GB_DEGR HR_DEGR HU_DEGR IE_DEGR IL_DEGR JP_DEGR KR_DEGR LV_DEGR NL_DEGR NO_DEGR NZ_DEGR PH_DEGR PL_DEGR PT_DEGR RU_DEGR SE_DEGR SI_DEGR TW_DEGR US_DEGR UY_DEGR VE_DEGR ZA_DEGR AU_PRTY CA_PRTY CH_PRTY CL_PRTY CZ_PRTY DE_PRTY DK_PRTY DO_PRTY ES_PRTY FI_PRTY FR_PRTY GB_PRTY HR_PRTY HU_PRTY IE_PRTY IL_PRTY JP_PRTY KR_PRTY LV_PRTY NL_PRTY NO_PRTY NZ_PRTY PH_PRTY PL_PRTY PT_PRTY RU_PRTY SE_PRTY SI_PRTY TW_PRTY US_PRTY UY_PRTY VE_PRTY ZA_PRTY{
rename `x' `x'06
} 


rename _all, upper 

*change value labels
capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'123"
la val `var' `var'123
} 


la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'


capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'"
la val `var' `var'
}

la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'

save "$path\DATASET_2006_1.dta", replace


********************************************************************************
*2007
********************************************************************************

use "$path\DATASET_2007.dta"

rename V1 study_number
rename V2 archive_version
rename V3 respondent_number
rename V4 country_sample
rename V5 country
gen year=2007


drop V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 V21 V22 V23 V24 V25 V26 V27 V28 V29 V30 V31 V32 V33 V34 V35 V36 V37 V38 V39 V40 V41 V42 V43 V44 V45 V46 V47 V48 V49 V50 V51 V52 V53 V54 V55 V56 V57 V58 V59 V60 V61 V62 V63 V64 V65 V66 V67 V68 V69 V70 V71 V72 V73

foreach x of varlist AR_DEGR AT_DEGR AU_DEGR BG_DEGR CH_DEGR CL_DEGR CY_DEGR CZ_DEGR DE_DEGR DO_DEGR FI_DEGR FLA_DEGR FR_DEGR GB_DEGR HR_DEGR HU_DEGR IE_DEGR IL_DEGR JP_DEGR KR_DEGR LV_DEGR MX_DEGR NO_DEGR NZ_DEGR PH_DEGR PL_DEGR RU_DEGR SE_DEGR SI_DEGR SK_DEGR TW_DEGR US_DEGR UY_DEGR ZA_DEGR AR_PRTY AT_PRTY AU_PRTY BG_PRTY CH_PRTY CL_PRTY CY_PRTY CZ_PRTY DE_PRTY DO_PRTY FI_PRTY FLA_PRTY FR_PRTY GB_PRTY HR_PRTY HU_PRTY IE_PRTY IL_PRTY JP_PRTY KR_PRTY LV_PRTY MX_PRTY NO_PRTY NZ_PRTY PH_PRTY PL_PRTY RU_PRTY SE_PRTY SI_PRTY SK_PRTY TW_PRTY US_PRTY UY_PRTY ZA_PRTY{
rename `x' `x'07
} 

rename _all, upper

*change value labels
capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'123"
la val `var' `var'123
} 


la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'


capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'"
la val `var' `var'
}

la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'

save "$path\DATASET_2007_1.dta", replace


********************************************************************************
*2008
********************************************************************************

use "$path\DATASET_2008.dta", clear

rename V1 study_number
rename V2 archive_version
rename V3 respondent_number
rename V4 country_sample
rename V5 country
gen year=2008


drop V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 V21 V22 V23 V24 V25 V26 V27 V28 V29 V30 V31 V32 V33 V34 V35 V36 V37 V38 V39 V40 V41 V42 V43 V44 V45 V46 V47 V48 V49 V50 V51 V52 V53 V54 V55 V56 V57 V58 V59 V60 V61 V62 V63 V64 V65 V66 V67 V68 V69 V70 V71 V72 V73 V74 V75 V76 V77 V78 V79 V80 V81 V82 V83 V84 V85 V86 V87 V88

foreach x of varlist AT_DEGR AU_DEGR BE_DEGR CH_DEGR CL_DEGR CY_DEGR CZ_DEGR DE_DEGR DK_DEGR DO_DEGR ES_DEGR FI_DEGR FR_DEGR GB_DEGR HR_DEGR HU_DEGR IE_DEGR IL_DEGR IT_DEGR JP_DEGR KR_DEGR LV_DEGR MX_DEGR NIR_DEGR NL_DEGR NO_DEGR NZ_DEGR PH_DEGR PL_DEGR PT_DEGR RU_DEGR SE_DEGR SI_DEGR SK_DEGR TR_DEGR TW_DEGR UA_DEGR US_DEGR UY_DEGR VE_DEGR ZA_DEGR AT_PRTY AU_PRTY BE_PRTY CH_PRTY CL_PRTY CY_PRTY CZ_PRTY DE_PRTY DK_PRTY DO_PRTY ES_PRTY FI_PRTY FR_PRTY GB_PRTY HR_PRTY HU_PRTY IE_PRTY IL_PRTY IT_PRTY JP_PRTY KR_PRTY LV_PRTY MX_PRTY NIR_PRTY NL_PRTY NO_PRTY NZ_PRTY PH_PRTY PL_PRTY PT_PRTY RU_PRTY SE_PRTY SI_PRTY SK_PRTY TR_PRTY TW_PRTY UA_PRTY US_PRTY UY_PRTY VE_PRTY ZA_PRTY{
rename `x' `x'08
}

rename _all, upper

*change value labels
capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'123"
la val `var' `var'123
} 

la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'

capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'"
la val `var' `var'
}

la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'

save "$path\DATASET_2008_1.dta", replace


********************************************************************************
*2010
********************************************************************************

use "$path\DATASET_2010.dta", clear

rename studyno study_number
rename version archive_version
rename c_sample country_sample
rename CASEID respondent_number

gen year=2010

drop v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 v17 v18 v19 v20 v21 v22 v23 v24 v25 v26 v27 v28 v29 v30 v31 v32 v33 v34 v35 v36 v37 v38 v39 v40 v41 v42 v43 v44 v45 v46 v47 v48 v49 v50 v51 v52 v53 v54 v55 v56 v57 v58 v59 v60 v61 v62 v63 v64 v65 v66

foreach x of varlist AR_DEGR AT_DEGR AU_DEGR BE_DEGR BG_DEGR CA_DEGR CH_DEGR CL_DEGR CZ_DEGR DE_DEGR DK_DEGR ES_DEGR FI_DEGR FR_DEGR GB_DEGR HR_DEGR IL_DEGR IS_DEGR JP_DEGR KR_DEGR LT_DEGR LV_DEGR MX_DEGR NL_DEGR NO_DEGR NZ_DEGR PH_DEGR PT_DEGR RU_DEGR SE_DEGR SI_DEGR SK_DEGR TR_DEGR TW_DEGR US_DEGR ZA_DEGR AR_PRTY AT_PRTY AU_PRTY BE_PRTY BG_PRTY CA_PRTY CH_PRTY CL_PRTY CZ_PRTY DE_PRTY DK_PRTY ES_PRTY FI_PRTY FR_PRTY GB_PRTY HR_PRTY IL_PRTY IS_PRTY JP_PRTY KR_PRTY LT_PRTY LV_PRTY MX_PRTY NL_PRTY NO_PRTY NZ_PRTY PH_PRTY PT_PRTY RU_PRTY SE_PRTY SI_PRTY SK_PRTY TR_PRTY TW_PRTY US_PRTY ZA_PRTY{
rename `x' `x'10
}

rename _all, upper

*change value labels
capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'123"
la val `var' `var'123
} 

la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'

capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'"
la val `var' `var'
}

la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'


save "$path\DATASET_2010_1.dta", replace


********************************************************************************
*2011
********************************************************************************

use "$path\DATASET_2011.dta", clear
rename V1 study_number
rename V2 archive_version
rename V3 country_sample
rename V4 country
rename CASEID respondent_number

gen year=2011

drop V5 CN_V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 V21 V22 V23 V24 V25 V26 V27 V28 V29 V30 V31 V32 V33 V34 V35 V36 V37 V38 V39 V40 V41 V42 V43 V44 V45 V46 V47 V48 V49 V50 V51 V52 V53 V54 V55 V56 V57 V58 V59 V60 V61 V62 V63 V64 V65 V66 V67 V68 V69

foreach x of varlist AU_DEGR BE_DEGR BG_DEGR CH_DEGR CL_DEGR CN_DEGR CZ_DEGR DE_DEGR DK_DEGR ES_DEGR FI_DEGR FR_DEGR GB_DEGR HR_DEGR IL_DEGR IT_DEGR JP_DEGR KR_DEGR LT_DEGR NL_DEGR NO_DEGR PH_DEGR PL_DEGR PT_DEGR RU_DEGR SE_DEGR SI_DEGR SK_DEGR TR_DEGR TW_DEGR US_DEGR ZA_DEGR AU_PRTY BE_PRTY BG_PRTY CH_PRTY CL_PRTY CN_PRTY CZ_PRTY DE_PRTY DK_PRTY ES_PRTY FI_PRTY FR_PRTY GB_PRTY HR_PRTY IL_PRTY IT_PRTY JP_PRTY KR_PRTY LT_PRTY NL_PRTY NO_PRTY PH_PRTY PL_PRTY PT_PRTY RU_PRTY SE_PRTY SI_PRTY SK_PRTY TR_PRTY TW_PRTY US_PRTY ZA_PRTY{
rename `x' `x'11
}

rename _all, upper

*change value labels
capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'123"
la val `var' `var'123
} 

la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'

capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'"
la val `var' `var'
}

la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'

save "$path\DATASET_2011_1.dta", replace


********************************************************************************
*2012
********************************************************************************

use "$path\DATASET_2012.dta", clear

rename V1 study_number
rename V2 archive_version
rename V3 country_sample
rename V4 country
rename CASEID respondent_number

gen year=2012


drop V5 ES_V5 V6 ES_V6 V7 ES_V7 V8 ES_V8 V9 ES_V9 V10 ES_V10 V11 ES_V11 V12 V13 V14 ES_V14 V15 ES_V15 V16 ES_V16 V17 ES_V17 V18 ES_V18 HU_V18 V19 ES_V19 HU_V19 V20 ES_V20 HU_V20 V21 V22 ES_V22 V23 ES_V23 V24 ES_V24 V25 ES_V25 V26 ES_V26 V27 ES_V27 V28 V29 V30 V31 V32 V33 V34 V35 V36 V37 V38 V39 V40 V41 V42 V43 V44 V45 V46 V47 V48 V49 V50 V51 V52 V53 V54 V55 V56 V57 V58 V59 V60 V61 V62 V63 V64 V65 V65a V66 V67

foreach x of varlist AR_DEGR AT_DEGR AU_DEGR BE_DEGR BG_DEGR CA_DEGR CH_DEGR CL_DEGR CN_DEGR CZ_DEGR DE_DEGR DK_DEGR ES_DEGR FI_DEGR FR_DEGR GB_DEGR HR_DEGR HU_DEGR IE_DEGR IL_DEGR IN_DEGR IS_DEGR JP_DEGR KR_DEGR LT_DEGR LV_DEGR MX_DEGR NL_DEGR NO_DEGR PH_DEGR PL_DEGR PT_DEGR RU_DEGR SE_DEGR SI_DEGR SK_DEGR TR_DEGR TW_DEGR US_DEGR VE_DEGR ZA_DEGR AR_PRTY AT_PRTY AU_PRTY BE_PRTY BG_PRTY CA_PRTY CH_PRTY CL_PRTY CN_PRTY CZ_PRTY DE_PRTY DK_PRTY ES_PRTY FI_PRTY FR_PRTY GB_PRTY HR_PRTY HU_PRTY IE_PRTY IL_PRTY IN_PRTY IS_PRTY JP_PRTY KR_PRTY LT_PRTY LV_PRTY MX_PRTY NL_PRTY NO_PRTY PH_PRTY PL_PRTY PT_PRTY RU_PRTY SE_PRTY SI_PRTY SK_PRTY TR_PRTY TW_PRTY US_PRTY VE_PRTY ZA_PRTY{
rename `x' `x'12
}

rename _all, upper

*change value labels
capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'123"
la val `var' `var'123
} 

la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'

capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'"
la val `var' `var'
}

la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'

save "$path\DATASET_2012_1.dta", replace


********************************************************************************
*2013
********************************************************************************

use "$path\DATASET_2013.dta", clear

rename V1 study_number
rename V2 archive_version
rename V3 country_sample
rename V4 country
rename CASEID respondent_number
gen year=2013

drop V5 V6 V7 V8 V9 ZA_V9 V10 ZA_V10 V11 ZA_V11 V12 ZA_V12 V13 ZA_V13 V14 ZA_V14 V15 ZA_V15 V16 ZA_V16 V17 V18 V19 V20 V21 V22 V23 V24 V25 V26 V27 V28 V29 V30 V31 V32 V33 V34 V35 V36 V37 V38 V39 V40 V41 V42 V43 V44 V45 V46 V47 V48 V49 V50 V51 V52 V53 V54 V55 V56 V57 V58 V59 V60 V61 V62 V63 V64 V65 V66 V67 V68 V69 V70

foreach x of varlist  BE_DEGR CH_DEGR CZ_DEGR DE_DEGR DK_DEGR EE_DEGR ES_DEGR FI_DEGR FR_DEGR GB_DEGR GE_DEGR HR_DEGR HU_DEGR IE_DEGR IL_DEGR IN_DEGR IS_DEGR JP_DEGR KR_DEGR LT_DEGR LV_DEGR MX_DEGR NO_DEGR PH_DEGR PT_DEGR RU_DEGR SE_DEGR SI_DEGR SK_DEGR TR_DEGR TW_DEGR US_DEGR ZA_DEGR BE_PRTY CH_PRTY CZ_PRTY DE_PRTY DK_PRTY EE_PRTY ES_PRTY FI_PRTY FR_PRTY GB_PRTY GE_PRTY HR_PRTY HU_PRTY IE_PRTY IL_PRTY IN_PRTY IS_PRTY JP_PRTY KR_PRTY LT_PRTY LV_PRTY MX_PRTY NO_PRTY PH_PRTY PT_PRTY RU_PRTY SE_PRTY SI_PRTY SK_PRTY TR_PRTY TW_PRTY US_PRTY ZA_PRTY{
rename `x' `x'13
}
rename ??_ETHN1 ??_ETHN

rename _all, upper

*change value labels
capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'123"
la val `var' `var'123
} 

la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'

capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'"
la val `var' `var'
}

la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'

save "$path\DATASET_2013_1.dta", replace


********************************************************************************
*2014
********************************************************************************

use "$path\DATASET_2014.dta", clear

rename V1 study_number
rename V2 archive_version
rename V3 country_sample
rename V4 country
rename CASEID respondent_number
gen year=2014

drop   V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 V21 V22 V23 V24 V25 V26 V27 V28 V29 V30 V31 V32 V33 V34 V35 V36 V37 V38 V39 V40 V41 V42 V43 V44 V45 V46 V47 V48 V49 V50 V51 V52 V53 V54 V55 V56 V57 V58 V59 V60 V61 V62 V63 V64 V65 CZ_V65 V66 CZ_V66 V67 CZ_V67 V68 CZ_V68

foreach x of varlist AT_DEGR AU_DEGR BE_DEGR CH_DEGR CL_DEGR CZ_DEGR DE_DEGR DK_DEGR ES_DEGR FI_DEGR FR_DEGR GB_DEGR GE_DEGR HR_DEGR HU_DEGR IL_DEGR IN_DEGR IS_DEGR JP_DEGR KR_DEGR LT_DEGR NL_DEGR NO_DEGR PH_DEGR PL_DEGR RU_DEGR SE_DEGR SI_DEGR SK_DEGR TR_DEGR TW_DEGR US_DEGR VE_DEGR ZA_DEGR AT_PRTY AU_PRTY BE_PRTY CH_PRTY CL_PRTY CZ_PRTY DE_PRTY DK_PRTY ES_PRTY FI_PRTY FR_PRTY GB_PRTY GE_PRTY HR_PRTY HU_PRTY IL_PRTY IN_PRTY IS_PRTY JP_PRTY KR_PRTY LT_PRTY NL_PRTY NO_PRTY PH_PRTY PL_PRTY RU_PRTY SE_PRTY SI_PRTY SK_PRTY TR_PRTY TW_PRTY US_PRTY VE_PRTY ZA_PRTY{
rename `x' `x'14
}
rename ??_ETHN1 ??_ETHN

rename _all, upper

*change value labels
capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'123"
la val `var' `var'123
} 

la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'

capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'"
la val `var' `var'
}

la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'


save "$path\DATASET_2014_1.dta", replace


********************************************************************************
*2015
********************************************************************************

use "$path\DATASET_2015.dta", clear

gen year=2015
rename studyno study_number
rename version archive_version
rename c_sample country_sample
rename CASEID respondent_number


drop  v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 V16 v17 v18 v19 v20 v21 v22 v23 v24 v25 v26 v27 v28 v29 v30 v31 v32 v33 v34 v35 v36 v37 v38 v39 v40 v41 v42 v43 v44 v45 v46 v47 v48 v49 v50 v51 v52 v53 v54 v55 v56 v57 v58 v59 v60 v61 v62 v63 v64 v65 v66 v67 v68 v69 v70 v71 v72 v73 v74 v75 v76 v77 v78 v79 v80 v81 v82 v83 v84 v85 v86 v87 v88 v89 v90 v91 v92 v93 v94 v95 v96 v97

foreach x of varlist AT_DEGR AU_DEGR BE_DEGR CH_DEGR CL_DEGR CN_DEGR CZ_DEGR DE_DEGR DK_DEGR EE_DEGR ES_DEGR FI_DEGR FR_DEGR GB_DEGR GE_DEGR HR_DEGR HU_DEGR IL_DEGR IN_DEGR IS_DEGR JP_DEGR LT_DEGR LV_DEGR MX_DEGR NO_DEGR NZ_DEGR PH_DEGR PL_DEGR RU_DEGR SE_DEGR SI_DEGR SK_DEGR SR_DEGR TW_DEGR US_DEGR VE_DEGR ZA_DEGR AT_PRTY AU_PRTY BE_PRTY CH_PRTY CL_PRTY CN_PRTY CZ_PRTY DE_PRTY DK_PRTY EE_PRTY ES_PRTY FI_PRTY FR_PRTY GB_PRTY GE_PRTY HR_PRTY HU_PRTY IL_PRTY IN_PRTY IS_PRTY JP_PRTY LT_PRTY LV_PRTY MX_PRTY NO_PRTY NZ_PRTY PH_PRTY PL_PRTY RU_PRTY SE_PRTY SI_PRTY SK_PRTY SR_PRTY TW_PRTY US_PRTY VE_PRTY ZA_PRTY{
rename `x' `x'15
}
rename ??_ETHN1 ??_ETHN

rename _all, upper

*change value labels
capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'123"
la val `var' `var'123
} 

la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'

capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'"
la val `var' `var'
}

la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'

save "$path\DATASET_2015_1.dta", replace


********************************************************************************
*2016
********************************************************************************

use "$path\DATASET_2016.dta", clear
gen year=2016
rename studyno study_number
rename version archive_version
rename c_sample country_sample
rename CASEID respondent_number

drop v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 v17 v18 v19 v20 v21 v22 v23 v24 v25 v26 v27 v28 v29 v30 v31 v32 v33 v34 v35 v36 v37 v38 v39 v40 v41 HU_v41 v42 HU_v42 v43 v44 v45 v46 NZ_v46 v47 v48 v49 v50 v51 v52 v53 v54 v55 v56 v57 v58 v59 v60 v61 v62 v63

foreach x of varlist AU_DEGR BE_DEGR CH_DEGR CL_DEGR CZ_DEGR DE_DEGR DK_DEGR ES_DEGR FI_DEGR FR_DEGR GB_DEGR GE_DEGR HR_DEGR HU_DEGR IL_DEGR IN_DEGR IS_DEGR JP_DEGR KR_DEGR LT_DEGR LV_DEGR NO_DEGR NZ_DEGR PH_DEGR RU_DEGR SE_DEGR SI_DEGR SK_DEGR SR_DEGR TH_DEGR TR_DEGR TW_DEGR US_DEGR VE_DEGR ZA_DEGR AU_PRTY BE_PRTY CH_PRTY CL_PRTY CZ_PRTY DE_PRTY DK_PRTY ES_PRTY FI_PRTY FR_PRTY GB_PRTY GE_PRTY HR_PRTY HU_PRTY IL_PRTY IN_PRTY IS_PRTY JP_PRTY KR_PRTY LV_PRTY LT_PRTY NO_PRTY NZ_PRTY PH_PRTY RU_PRTY SE_PRTY SI_PRTY SK_PRTY SR_PRTY TH_PRTY TR_PRTY TW_PRTY US_PRTY VE_PRTY ZA_PRTY{
rename `x' `x'16
}
rename ??_ETHN1 ??_ETHN

rename _all, upper

*change value labels
capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'123"
la val `var' `var'123
} 

la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'

capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'"
la val `var' `var'
}

la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'

save "$path\DATASET_2016_1.dta", replace


********************************************************************************
*2017
********************************************************************************

use "$path\DATASET_2017.dta", clear
gen year=2017
rename studyno study_number
rename version archive_version
rename c_sample country_sample
rename CASEID respondent_number

drop v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 v17 v18 v19 v20 v21 v22 v23 v24 v25 v26 v27 v28 v29 v30 v31 v32 v33 v34 v35 v36 v37 v38 v39 v40 v41 v42 v43 v44 v45 v46 v47 v48 v49 v50 v51 v52 v53 v54 v55 v56 v57 v58 v59 v60 v61 v62 v63 v64 v65 v66

rename v67 SPDEGREE

foreach x of varlist AT_DEGR AU_DEGR CH_DEGR CN_DEGR CZ_DEGR DE_DEGR DK_DEGR ES_DEGR FI_DEGR FR_DEGR GB_DEGR HR_DEGR HU_DEGR IL_DEGR IN_DEGR IS_DEGR JP_DEGR LT_DEGR MX_DEGR NZ_DEGR PH_DEGR RU_DEGR SE_DEGR SI_DEGR SK_DEGR SR_DEGR TH_DEGR TW_DEGR US_DEGR ZA_DEGR AT_PRTY AU_PRTY CH_PRTY CN_PRTY CZ_PRTY DE_PRTY DK_PRTY ES_PRTY FI_PRTY FR_PRTY GB_PRTY HR_PRTY HU_PRTY IL_PRTY IN_PRTY IS_PRTY JP_PRTY LT_PRTY MX_PRTY NZ_PRTY PH_PRTY RU_PRTY SE_PRTY SI_PRTY SK_PRTY SR_PRTY TH_PRTY TW_PRTY US_PRTY ZA_PRTY{
rename `x' `x'17
}
rename ??_ETHN1 ??_ETHN

rename _all, upper

*change value labels
capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'123"
la val `var' `var'123
} 

la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'

capt which labvalclone
if _rc ssc inst labutil

//get all vars with value labels
ds, has(vallabel)

//cycle thru list and change val label name
foreach var of varlist `r(varlist)'{
labvalclone "`:val lab `var''" "`var'"
la val `var' `var'
}

la def mylabel 1 "unused"
la def mylabel2 3 "unused"
labelbook, problems
la drop `r(notused)'

save "$path\DATASET_2017_1.dta", replace


*******************************************************************************
*APPEND ANNUAL DATASETS 2002-2017 to DATASET_inequalities1987-2009
*******************************************************************************

use "$path\DATASET_inequalities1987-2009.dta", clear

*2002
append using "$path\DATASET_2002_1.dta", force

*2003
append using "$path\DATASET_2003_1.dta", force

*2004
append using "$path\DATASET_2004_1.dta", force

*2005
append using "$path\DATASET_2005_1.dta", force

 *2006
append using "$path\DATASET_2006_1.dta", force

 *2007
append using "$path\DATASET_2007_1.dta", force

*2008
append using "$path\DATASET_2008_1.dta", force

*2010
append using "$path\DATASET_2010_1.dta", force

*2011
append using "$path\DATASET_2011_1.dta", force

*2012
append using "$path\DATASET_2012_1.dta", force

*2013
append using "$path\DATASET_2013_1.dta", force

*2014
append using "$path\DATASET_2014_1.dta", force

*2015
append using "$path\DATASET_2015_1.dta", force

*2016
append using "$path\DATASET_2016_1.dta", force

*2017
append using "$path\DATASET_2017_1.dta", force


*recode COUNTRY for 2005 (only COUNTRY_SAMPLE AVAILABLE)
replace COUNTRY=36 if YEAR==2005 & COUNTRY_SAMPLE==1
replace COUNTRY=276 if YEAR==2005 & COUNTRY_SAMPLE==2
replace COUNTRY=276 if YEAR==2005 & COUNTRY_SAMPLE==3
replace COUNTRY=82601 if YEAR==2005 & COUNTRY_SAMPLE==4
replace COUNTRY=840 if YEAR==2005 & COUNTRY_SAMPLE==6
replace COUNTRY=348 if YEAR==2005 & COUNTRY_SAMPLE==8
replace COUNTRY=372 if YEAR==2005 & COUNTRY_SAMPLE==10
replace COUNTRY=528 if YEAR==2005 & COUNTRY_SAMPLE==11
replace COUNTRY=578 if YEAR==2005 & COUNTRY_SAMPLE==12
replace COUNTRY=752 if YEAR==2005 & COUNTRY_SAMPLE==13
replace COUNTRY=203 if YEAR==2005 & COUNTRY_SAMPLE==14
replace COUNTRY=705 if YEAR==2005 & COUNTRY_SAMPLE==15
replace COUNTRY=100 if YEAR==2005 & COUNTRY_SAMPLE==17
replace COUNTRY=643 if YEAR==2005 & COUNTRY_SAMPLE==18
replace COUNTRY=554 if YEAR==2005 & COUNTRY_SAMPLE==19
replace COUNTRY=124 if YEAR==2005 & COUNTRY_SAMPLE==20
replace COUNTRY=608 if YEAR==2005 & COUNTRY_SAMPLE==21
replace COUNTRY=376 if YEAR==2005 & COUNTRY_SAMPLE==22
replace COUNTRY=392 if YEAR==2005 & COUNTRY_SAMPLE==24
replace COUNTRY=724 if YEAR==2005 & COUNTRY_SAMPLE==25
replace COUNTRY=428 if YEAR==2005 & COUNTRY_SAMPLE==26
replace COUNTRY=250 if YEAR==2005 & COUNTRY_SAMPLE==28
replace COUNTRY=196 if YEAR==2005 & COUNTRY_SAMPLE==29
replace COUNTRY=620 if YEAR==2005 & COUNTRY_SAMPLE==30
replace COUNTRY=208 if YEAR==2005 & COUNTRY_SAMPLE==32
replace COUNTRY=756 if YEAR==2005 & COUNTRY_SAMPLE==33
replace COUNTRY=56 if YEAR==2005 & COUNTRY_SAMPLE==34
replace COUNTRY=246 if YEAR==2005 & COUNTRY_SAMPLE==37
replace COUNTRY=484 if YEAR==2005 & COUNTRY_SAMPLE==38
replace COUNTRY=158 if YEAR==2005 & COUNTRY_SAMPLE==39
replace COUNTRY=710 if YEAR==2005 & COUNTRY_SAMPLE==40
replace COUNTRY=410 if YEAR==2005 & COUNTRY_SAMPLE==41
replace COUNTRY=214 if YEAR==2005 & COUNTRY_SAMPLE==43

label define COUNTRY 36 "AU-Australia" 40 "AT-Austria" 56 "BE-Belgium/Flanders" 76 "BR-Brazil" 100 "BG-Bulgaria" 124 "CA-Canada" 152 "CL-Chile" 158 "TW-Taiwan" 196 "CY-Cyprus" 203 "CZ-Czech Republic" 208 "DK-Denmark" 246 "FI-Finland" 250 "FR-France" 276 "DE-Germany" 348 "HU-Hungary" 372 "IE-Ireland" 376 "IL-Israel" 380 "IT-Italy" 392 "JP-Japan" 410 "KR-South Korea" 428 "LV-Latvia" 484 "MX-Mexico" 528 "NL-Netherlands" 554 "NZ-New Zealand" 578 "NO-Norway" 608 "PH-Philippines" 616 "PL-Poland" 620 "PT-Portugal" 643 "RU-Russia" 703 "SK-Slovak Republic" 705 "SI-Slovenia" 710 "ZA-SouthAfrica" 724 "ES-Spain" 752 "SE-Sweden" 756 "CH-Switzerland" 826 "UK-United Kingdom" 840 "US-United States" 858 "UY-Uruguay" 862 "VE-Venezuela" 82601 "United Kingdom (Great Britain only)" 214 "DO-Dominican Republic", replace



********************************************************************************
*code subjective social status
********************************************************************************
recode TOPBOT (0=.) (97=.) (98=.) (99=.)
gen TOPBOT100=[(TOPBOT-1)*100]/9

recode COUNTRY (826=82601) if YEAR!=2008
replace COUNTRY=82601 if YEAR==2008 & COUNTRY_SAMPLE==82601
replace COUNTRY=82602 if YEAR==2008 & COUNTRY_SAMPLE==82602


****************************************************************
*code education
****************************************************************
recode DEGREE (7=.) (8=.) (9=.)
recode DEGREE (6=5) if YEAR==2011 | YEAR==2012 | YEAR==2013 | YEAR==2014 | YEAR==2015 | YEAR==2016 | YEAR==2017

gen ed_level=.
replace ed_level=1 if DEGREE==0 | DEGREE==1 | DEGREE==2
replace ed_level=3 if  DEGREE==5 
replace ed_level=2 if DEGREE==3 |DEGREE==4 
label variable ed_level "three levels for respondent education"
label define ed_level 1 "no more than compulsory education" 2 "upper-secondary and post-upper-secondary education" 3 "tertiary university education", replace
label value ed_level ed_level
fre ed_level

********************************************************************************
*code variable on r's subjective social status compared to father's
********************************************************************************
recode V67 (6=.) (7=.)


********************************************************************************
*code gender
********************************************************************************
gen SEX01=.
replace SEX01=1 if SEX==1
replace SEX01=0 if SEX==2
label define SEX01 1"male" 0"female"
label value SEX01 SEX01

********************************************************************************
*coding country labels
********************************************************************************
gen country=""
replace country="HU" if COUNTRY==348
replace country="NO" if COUNTRY==578
replace country="PL" if COUNTRY==616
replace country="SE" if COUNTRY==752
replace country="CH" if COUNTRY==756
replace country="US" if COUNTRY==840
replace country="DE" if COUNTRY==276
replace country="GB" if COUNTRY==82601

********************************************************************************
*armonisation of the value labels of YEAR:
********************************************************************************

label drop YEAR
save "$path\DATASET_1987-2018.dta", replace
		


***********************************************************************
*********************CLASS SCHEMA**************************************
***********************************************************************



*******************************************************************************
* Create 16-Class schema, 8-Class schema and 5-Class schema
* Data: ISSP cumulative dataset Social Inequalities (1987, 1992, 1999, 2009), annual datasets 1997-2013 (containing ISCO88 codes)
*******************************************************************************
keep if YEAR<2014
save "$path\DATASET_1987-2013_class.dta", replace
use "$path\DATASET_1987-2013_class.dta", clear
	
*******************************************************************************
* Respondent's Oesch class position
* Recode and create variables used to construct class variable for respondents
* Variables used to construct class variable for respondents: ISCO88, NEMPLOY, SELFEMP, EMPREL, WRKTYPE
* If using a cumulation of annual datasets including 2000 and 2010, it is also necessary to generate a YEAR variable
*******************************************************************************

**** Recode occupation variable (isco88 com 4-digit) for respondents

tab ISCO88, m
 
recode ISCO88 (missing=-9), copyrest gen(isco88_mainjob)
recode isco88_mainjob (0=-9)
label variable isco88_mainjob "Current occupation of respondent - isco88 4-digit"
tab isco88_mainjob

 
**** Recode employment status for respondents
 
recode NEMPLOY (9995=0)(1/9=1)(10/9990=2)(.=.) (.a=.) (.n=.) (9997=.) (9998=.) (9999=.), gen(emplno_r)
recode emplno_r (0=2) if NEMPLOY==9995 & YEAR==2010
recode emplno_r (99996=0) if NEMPLOY==99996 & YEAR==2000
label define emplno_r ///
0 "0 employees" ///
1 "1-9 employees" ///
2 "10+ employees"
label value emplno_r emplno_r
tab emplno_r
***NB: In 2002, 2003 and 2007 it is not possible to identify self-employed respondents with no emoloyee: in these years there is no "0" nor corresponding value in the variable "NEMPLOY". Moreover, in these years there is no variable distinguishing between self-employed with emoloyees and self-employed without employees.
				
				
gen selfemp_r=9
replace selfemp_r=1 if emplno_r==1 | emplno_r==2 | SELFEMP==1
replace selfemp_r=2 if SELFEMP==2 
replace selfemp_r=1 if emplno_r==1 | emplno_r==2 | WRKTYPE==4 
replace selfemp_r=2 if WRKTYPE==1| WRKTYPE==2 | WRKTYPE==3 | WRKTYPE==5 | WRKTYPE==6 
replace selfemp_r=1 if emplno_r==1 | emplno_r==2 |  EMPREL==2 | EMPREL==3 | EMPREL==4
replace selfemp_r=2 if EMPREL==1
	
label define selfemp_r 1"Self-employed" 2 "Employee" 9 "Missing"
label value selfemp_r selfemp_r			
tab selfemp_r

gen selfem_mainjob=.
replace selfem_mainjob=1 if selfemp_r==2 | selfemp_r==9
replace selfem_mainjob=2 if selfemp_r==1 & (emplno_r==0 | emplno_r==.)
replace selfem_mainjob=2 if EMPREL==2 | EMPREL==4
	
replace selfem_mainjob=3 if (selfemp_r==1 | selfemp_r==9) & emplno_r==1 
replace selfem_mainjob=4 if (selfemp_r==1 | selfemp_r==9) & emplno_r==2
label variable selfem_mainjob "Employment status for respondents"
label define selfem_mainjob 1 "Not self-employed" 2 "Self-empl without employees" 3 "Self-empl with 1-9 employees" 4 "Self-empl with 10 or more" 
label value selfem_mainjob selfem_mainjob
tab selfem_mainjob, m
                                 
***NB1: selfem_mainjob=1 if selfemp_r==9 -> people we don't know if they are self-employed or not are considered to be employees.
***NB2: selfem_mainjob=2 selfemp_r==1 & emplno_r==. -> self-employed people we don't know how many employees they have are considered to be self-employed without employees.


*************************************************
* Create Oesch class schema for respondents
* Create class16_r class8_r class5_r
* Using isco88_mainjob and selfem_mainjob
*************************************************

gen class16_r = -9
 
* Large employers (1)
 
replace class16_r=1 if selfem_mainjob==4
 
* Self-employed professionals (2)
 
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco88_mainjob >= 2000 & isco88_mainjob <= 2229) 
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco88_mainjob >= 2300 & isco88_mainjob <= 2470)

* Small business owners with employees (3)
 
replace class16_r=3 if (selfem_mainjob==3) & (isco88_mainjob >= 1000 & isco88_mainjob <= 1999)
replace class16_r=3 if (selfem_mainjob==3) & (isco88_mainjob >= 3000 & isco88_mainjob <= 9333)
replace class16_r=3 if (selfem_mainjob==3) & (isco88_mainjob == 2230)

* Small business owners without employees (4)
 
replace class16_r=4 if (selfem_mainjob==2) & (isco88_mainjob >= 1000 & isco88_mainjob <= 1999)
replace class16_r=4 if (selfem_mainjob==2) & (isco88_mainjob >= 3000 & isco88_mainjob <= 9333)
replace class16_r=4 if (selfem_mainjob==2) & (isco88_mainjob == 2230)
 

* Technical experts (5)
 
replace class16_r=5 if (selfem_mainjob==1) & (isco88_mainjob >= 2000 & isco88_mainjob <= 2213)

* Technicians (6)
 
replace class16_r=6 if (selfem_mainjob==1) & (isco88_mainjob >= 3000 & isco88_mainjob <= 3152)
replace class16_r=6 if (selfem_mainjob==1) & (isco88_mainjob >= 3210 & isco88_mainjob <= 3213)
replace class16_r=6 if (selfem_mainjob==1) & (isco88_mainjob == 3434)
replace class16_r=6 if (selfem_mainjob==1) & (isco88_mainjob == 7900)

* Skilled manual (7)

replace class16_r=7 if (selfem_mainjob==1) & (isco88_mainjob >= 6000 & isco88_mainjob <= 7450)
replace class16_r=7 if (selfem_mainjob==1) & (isco88_mainjob >= 7500 & isco88_mainjob <= 7510)
replace class16_r=7 if (selfem_mainjob==1) & (isco88_mainjob >= 8310 & isco88_mainjob <= 8312)
replace class16_r=7 if (selfem_mainjob==1) & (isco88_mainjob >= 8324 & isco88_mainjob <= 8330)
replace class16_r=7 if (selfem_mainjob==1) & (isco88_mainjob >= 8332 & isco88_mainjob <= 8340)
replace class16_r=7 if (selfem_mainjob==1) & (isco88_mainjob == 7520)
replace class16_r=7 if (selfem_mainjob==1) & (isco88_mainjob == 8341)

* Low-skilled manual (8)
 
replace class16_r=8 if (selfem_mainjob==1) & (isco88_mainjob >= 8000 & isco88_mainjob <= 8300)
replace class16_r=8 if (selfem_mainjob==1) & (isco88_mainjob >= 8320 & isco88_mainjob <= 8321)
replace class16_r=8 if (selfem_mainjob==1) & (isco88_mainjob == 8331)
replace class16_r=8 if (selfem_mainjob==1) & (isco88_mainjob >= 9153 & isco88_mainjob <= 9333)
replace class16_r=8 if (selfem_mainjob==1) & (isco88_mainjob == 8400)
replace class16_r=8 if (selfem_mainjob==1) & (isco88_mainjob == 7530)


* Higher-grade managers and administrators (9)
 
replace class16_r=9 if (selfem_mainjob==1) & (isco88_mainjob >= 1000 & isco88_mainjob <= 1239)
replace class16_r=9 if (selfem_mainjob==1) & (isco88_mainjob >= 2400 & isco88_mainjob <= 2429)
replace class16_r=9 if (selfem_mainjob==1) & (isco88_mainjob == 2441)
replace class16_r=9 if (selfem_mainjob==1) & (isco88_mainjob == 2470)

* Lower-grade managers and administrators (10) - "new" code ISCO (3439)

replace class16_r=10 if (selfem_mainjob==1) & (isco88_mainjob >= 1300 & isco88_mainjob <= 1412)
replace class16_r=10 if (selfem_mainjob==1) & (isco88_mainjob >= 3400 & isco88_mainjob <= 3433)
replace class16_r=10 if (selfem_mainjob==1) & (isco88_mainjob >= 3439 & isco88_mainjob <= 3451)
replace class16_r=10 if (selfem_mainjob==1) & (isco88_mainjob >= 1240 & isco88_mainjob <= 1252)
replace class16_r=10 if (selfem_mainjob==1) & (isco88_mainjob ==1252)


* Skilled clerks (11)

replace class16_r=11 if (selfem_mainjob==1) & (isco88_mainjob >= 4000 & isco88_mainjob <= 4112)
replace class16_r=11 if (selfem_mainjob==1) & (isco88_mainjob >= 4114 & isco88_mainjob <= 4210)
replace class16_r=11 if (selfem_mainjob==1) & (isco88_mainjob >= 4212 & isco88_mainjob <= 4222)

* Unskilled clerks (12)

replace class16_r=12 if (selfem_mainjob==1) & (isco88_mainjob == 4113)
replace class16_r=12 if (selfem_mainjob==1) & (isco88_mainjob == 4211)
replace class16_r=12 if (selfem_mainjob==1) & (isco88_mainjob == 4223)

* Socio-cultural professionals (13)
 
replace class16_r=13 if (selfem_mainjob==1) & (isco88_mainjob >= 2220 &  isco88_mainjob <= 2229)
replace class16_r=13 if (selfem_mainjob==1) & (isco88_mainjob >= 2300 &  isco88_mainjob <= 2323)
replace class16_r=13 if (selfem_mainjob==1) & (isco88_mainjob >= 2340 &  isco88_mainjob <= 2359)
replace class16_r=13 if (selfem_mainjob==1) & (isco88_mainjob >= 2430 &  isco88_mainjob <= 2440)
replace class16_r=13 if (selfem_mainjob==1) & (isco88_mainjob >= 2442 &  isco88_mainjob <= 2443)
replace class16_r=13 if (selfem_mainjob==1) & (isco88_mainjob == 2445)
replace class16_r=13 if (selfem_mainjob==1) & (isco88_mainjob == 2451)
replace class16_r=13 if (selfem_mainjob==1) & (isco88_mainjob == 2460)
replace class16_r=13 if (selfem_mainjob==1) & (isco88_mainjob == 3491)
replace class16_r=13 if (selfem_mainjob==1) & (isco88_mainjob == 3492)

* Socio-cultural semi-professionals (14)
 
replace class16_r=14 if (selfem_mainjob==1) & (isco88_mainjob == 2230)
replace class16_r=14 if (selfem_mainjob==1) & (isco88_mainjob >= 2330 & isco88_mainjob <= 2332)
replace class16_r=14 if (selfem_mainjob==1) & (isco88_mainjob == 2444)
replace class16_r=14 if (selfem_mainjob==1) & (isco88_mainjob >= 2446 & isco88_mainjob <= 2450)
replace class16_r=14 if (selfem_mainjob==1) & (isco88_mainjob >= 2452 & isco88_mainjob <= 2455)
replace class16_r=14 if (selfem_mainjob==1) & (isco88_mainjob == 3200)
replace class16_r=14 if (selfem_mainjob==1) & (isco88_mainjob >= 3220 & isco88_mainjob <= 3224)
replace class16_r=14 if (selfem_mainjob==1) & (isco88_mainjob == 3226)
replace class16_r=14 if (selfem_mainjob==1) & (isco88_mainjob >= 3229 & isco88_mainjob <= 3342)
replace class16_r=14 if (selfem_mainjob==1) & (isco88_mainjob >= 3460 & isco88_mainjob <= 3472)
replace class16_r=14 if (selfem_mainjob==1) & (isco88_mainjob == 3480)
replace class16_r=14 if (selfem_mainjob==1) & (isco88_mainjob >=2500 & isco88_mainjob<=2519)


* Skilled service (15)

replace class16_r=15 if (selfem_mainjob==1) & (isco88_mainjob == 3225)
replace class16_r=15 if (selfem_mainjob==1) & (isco88_mainjob >= 3227 & isco88_mainjob <= 3228)
replace class16_r=15 if (selfem_mainjob==1) & (isco88_mainjob >= 3473 & isco88_mainjob <= 3475)
replace class16_r=15 if (selfem_mainjob==1) & (isco88_mainjob >= 5000 & isco88_mainjob <= 5113)
replace class16_r=15 if (selfem_mainjob==1) & (isco88_mainjob == 5122)
replace class16_r=15 if (selfem_mainjob==1) & (isco88_mainjob >= 5131 & isco88_mainjob <= 5132)
replace class16_r=15 if (selfem_mainjob==1) & (isco88_mainjob >= 5140 & isco88_mainjob <= 5141)
replace class16_r=15 if (selfem_mainjob==1) & (isco88_mainjob == 5143)
replace class16_r=15 if (selfem_mainjob==1) & (isco88_mainjob >= 5160 & isco88_mainjob <= 5223)
replace class16_r=15 if (selfem_mainjob==1) & (isco88_mainjob == 8323)

* Low-skilled service (16)
 
replace class16_r=16 if (selfem_mainjob==1) & (isco88_mainjob >= 5120 & isco88_mainjob <= 5121)
replace class16_r=16 if (selfem_mainjob==1) & (isco88_mainjob >= 5123 & isco88_mainjob <= 5130)
replace class16_r=16 if (selfem_mainjob==1) & (isco88_mainjob >= 5133 & isco88_mainjob <= 5139)
replace class16_r=16 if (selfem_mainjob==1) & (isco88_mainjob == 5142)
replace class16_r=16 if (selfem_mainjob==1) & (isco88_mainjob == 5149)
replace class16_r=16 if (selfem_mainjob==1) & (isco88_mainjob == 5150)
replace class16_r=16 if (selfem_mainjob==1) & (isco88_mainjob == 5151)
replace class16_r=16 if (selfem_mainjob==1) & (isco88_mainjob == 5152)
replace class16_r=16 if (selfem_mainjob==1) & (isco88_mainjob == 5230)
replace class16_r=16 if (selfem_mainjob==1) & (isco88_mainjob == 8322)
replace class16_r=16 if (selfem_mainjob==1) & (isco88_mainjob >= 9000 & isco88_mainjob <= 9152)


***NB: a missing value in class16_r when isco88_mainjob!=. means that the value of selfem_mainjob was not coherent with the job type


mvdecode class16_r, mv(-9)
label variable class16_r "Respondent's Oesch class position - 16 classes"
label define class16_r ///
1 "Large employers" ///
2 "Self-employed professionals" ///
3 "Small business owners with employees" ///
4 "Small business owners without employees" ///
5 "Technical experts" ///
6 "Technicians" ///
7 "Skilled manual" ///
8 "Low-skilled manual" ///
9 "Higher-grade managers and administrators" ///
10 "Lower-grade managers and administrators" ///
11 "Skilled clerks" ///
12 "Unskilled clerks" ///
13 "Socio-cultural professionals" ///
14 "Socio-cultural semi-professionals" ///
15 "Skilled service" ///
16 "Low-skilled service"
label value class16_r class16_r
tab class16_r
 
recode class16_r (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8), gen(class8_r)
label variable class8_r "Respondent's Oesch class position - 8 classes"
label define class8_r ///
1 "Self-employed professionals and large employers" ///
2 "Small business owners" ///
3 "Technical (semi-)professionals" ///
4 "Production workers" ///
5 "(Associate) managers" ///
6 "Clerks" ///
7 "Socio-cultural (semi-)professionals" ///
8 "Service workers"
label value class8_r class8_r
tab class8_r

recode class16_r (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5), gen(class5_r)
label variable class5_r "Respondent's Oesch class position - 5 classes"
label define  class5_r ///
1 "Higher-grade service class" ///
2 "Lower-grade service class" ///
3 "Small business owners" ///
4 "Skilled workers" ///
5 "Unskilled workers"
label value class5_r class5_r
tab class5_r


*******************************************************************************
* Partner's Oesch class position
* Recode and create variables used to construct class variable for partners
* Variables used to construct class variable for partners: SPISCO88, SPSELFEM, SPWRKTYP (only for year 2002-2008), SPEMPREL (only for years 2010-2013)
* NB: Partners we don't know if they are self-employed or not are considered to be employees.
*******************************************************************************

recode SPISCO88 (missing=-9), copyrest gen(isco88_partner)
recode isco88_partner (0=-9)
label variable isco88_partner "Current occupation of partner - isco88 4-digit"

gen selfem_partner=9
replace selfem_partner=1 if SPSELFEM==1
replace selfem_partner=2 if SPSELFEM==2		

replace selfem_partner =1 if SPWRKTYP==4

replace selfem_partner=1 if SPEMPREL==2 | SPEMPREL==3 | SPEMPREL==4 | SPEMPREL==5
replace selfem_partner=2 if SPEMPREL==1

label define selfem_partner 1"Self-employed" 2 "Employee" 9 "Missing"
label value selfem_partner selfem_partner	


*************************************************
* Create Oesch class schema for partners
* Create class16_p class8_p class5_p
* Using isco88_partner and selfem_partner
*************************************************

gen class16_p = -9

* Large employers (1)

replace class16_p=1 if (selfem_partner==1) & (isco88_partner >= 1200 & isco88_partner <= 1239)

* Self-employed professionals (2)

replace class16_p=2 if (selfem_partner==1) & (isco88_partner >= 2000 & isco88_partner <= 2470)

* Small business owners with employees (3)

replace class16_p=3 if (selfem_partner==1) & (isco88_partner >= 1000 & isco88_partner <= 1143)
replace class16_p=3 if (selfem_partner==1) & (isco88_partner >= 1300 & isco88_partner <= 1319)

* Small business owners without employees (4)

replace class16_p=4 if (selfem_partner==1) & (isco88_partner >= 3000 & isco88_partner <= 9333)

 * Technical experts (5)

replace class16_p=5 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 2000 & isco88_partner <= 2213)

* Technicians (6)

replace class16_p=6 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 3000 & isco88_partner <= 3152)
replace class16_p=6 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 3210 & isco88_partner <= 3213)
replace class16_p=6 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 3434)
replace class16_p=6 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 7900)

* Skilled manual (7)

replace class16_p=7 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 6000 & isco88_partner <= 7442)
replace class16_p=7 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 7500 & isco88_partner <= 7520)
replace class16_p=7 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 8310 & isco88_partner <= 8312)
replace class16_p=7 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 8324 & isco88_partner <= 8330)
replace class16_p=7 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 8332 & isco88_partner <= 8341)

* Low-skilled manual (8)

replace class16_p=8 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 8000 & isco88_partner <= 8300)
replace class16_p=8 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 8320 & isco88_partner <= 8321)
replace class16_p=8 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 8331)
replace class16_p=8 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 8400)
replace class16_p=8 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 9153 & isco88_partner <= 9333)

* Higher-grade managers and administrators (9)

replace class16_p=9 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 1000 & isco88_partner <= 1239)
replace class16_p=9 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 2400 & isco88_partner <= 2429)
replace class16_p=9 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 2441)
replace class16_p=9 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 2470)

 * Lower-grade managers and administrators (10) - "new" code ISCO (3439)

replace class16_p=10 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 1300 & isco88_partner <= 1320)
replace class16_p=10 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 3400 & isco88_partner <= 3433)
replace class16_p=10 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 3439 & isco88_partner <= 3451)
replace class16_p=10 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 1240 & isco88_partner <= 1252)
replace class16_p=10 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 1320 & isco88_partner <= 1412)


 * Skilled clerks (11)

replace class16_p=11 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 4000 & isco88_partner <= 4112)
replace class16_p=11 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 4114 & isco88_partner <= 4210)
replace class16_p=11 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 4212 & isco88_partner <= 4222)

* Unskilled clerks (12)

replace class16_p=12 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 4113)
replace class16_p=12 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 4211)
replace class16_p=12 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 4223)

* Socio-cultural professionals (13)

replace class16_p=13 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 2220 & isco88_partner <= 2229)
replace class16_p=13 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 2300 & isco88_partner <= 2323)
replace class16_p=13 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 2340 & isco88_partner <= 2359)
replace class16_p=13 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 2430 & isco88_partner <= 2440)
replace class16_p=13 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 2442 & isco88_partner <= 2443)
replace class16_p=13 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 2445)
replace class16_p=13 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 2451)
replace class16_p=13 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 2460)
replace class16_p=13 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 3491)

* Socio-cultural semi-professionals (14)

replace class16_p=14 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 2230)
replace class16_p=14 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 2330 & isco88_partner <= 2332)
replace class16_p=14 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 2444)
replace class16_p=14 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 2446 & isco88_partner <= 2450)
replace class16_p=14 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 2452 & isco88_partner <= 2455)
replace class16_p=14 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 3200)
replace class16_p=14 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 3220 & isco88_partner <= 3224)
replace class16_p=14 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 3226)
replace class16_p=14 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 3229 & isco88_partner <= 3342)
replace class16_p=14 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 3460 & isco88_partner <= 3472)
replace class16_p=14 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 3480)
replace class16_p=14 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner==2500 |isco88_partner==2511 | isco88_partner==2512| isco88_partner==2513 | isco88_partner==2519)


* Skilled service (15)

replace class16_p=15 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 3225)
replace class16_p=15 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 3227 & isco88_partner <= 3228)
replace class16_p=15 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 3473 & isco88_partner <= 3475)
replace class16_p=15 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 5000 & isco88_partner <= 5113)
replace class16_p=15 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 5122)
replace class16_p=15 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 5131 & isco88_partner <= 5132)
replace class16_p=15 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 5140 & isco88_partner <= 5141)
replace class16_p=15 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 5143)
replace class16_p=15 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 5160 & isco88_partner <= 5223)
replace class16_p=15 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 8323)

* Low-skilled service (16)

replace class16_p=16 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 5120 & isco88_partner <= 5121)
replace class16_p=16 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 5123 & isco88_partner <= 5130)
replace class16_p=16 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 5133 & isco88_partner <= 5139)
replace class16_p=16 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 5142)
replace class16_p=16 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 5149)
replace class16_p=16 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >=5150 & isco88_partner <=5152)
replace class16_p=16 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 5230)
replace class16_p=16 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner == 8322)
replace class16_p=16 if (selfem_partner==2 | selfem_partner==9) & (isco88_partner >= 9000 & isco88_partner <= 9152)


mvdecode class16_p, mv(-9)
label variable class16_p "Partner's Oesch class position - 16 classes"
label define class16_p ///
1 "Large employers" ///
2 "Self-employed professionals" ///
3 "Small business owners with employees" ///
4 "Small business owners without employees" ///
5 "Technical experts" ///
6 "Technicians" ///
7 "Skilled manual" ///
8 "Low-skilled manual" ///
9 "Higher-grade managers and administrators" ///
10 "Lower-grade managers and administrators" ///
11 "Skilled clerks" ///
12 "Unskilled clerks" ///
13 "Socio-cultural professionals" ///
14 "Socio-cultural semi-professionals" ///
15 "Skilled service" ///
16 "Low-skilled service"
label value class16_p class16_p
tab class16_p

recode class16_p (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8), gen(class8_p)
label variable class8_p "Partner's Oesch class position - 8 classes"
label define class8_p ///
1 "Self-employed professionals and large employers" ///
2 "Small business owners" ///
3 "Technical (semi-)professionals" ///
4 "Production workers" ///
5 "(Associate) managers" ///
6 "Clerks" ///
7 "Socio-cultural (semi-)professionals" ///
8 "Service workers"
label value class8_p class8_p
tab class8_p

recode class16_p (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5), gen(class5_p)
label variable class5_p "Partner's Oesch class position - 5 classes"
label define  class5_p ///
1 "Higher-grade service class" ///
2 "Lower-grade service class" ///
3 "Small business owners" ///
4 "Skilled workers" ///
5 "Unskilled workers"
label value class5_p class5_p
tab class5_p


*******************************************************************************
 * Final Oesch class position
 * Merge two class variables (respondents and partners)
 * Assign the partner's Oesch class position if the respondent's Oesch class position is missing
*******************************************************************************

gen class16=class16_r
replace class16=class16_p if class16_r==.

label variable class16 "Final Oesch class position - 16 classes"
label define class16 ///
1 "Large employers" ///
2 "Self-employed professionals" ///
3 "Small business owners with employees" ///
4 "Small business owners without employees" ///
5 "Technical experts" ///
6 "Technicians" ///
7 "Skilled manual" ///
8 "Low-skilled manual" ///
9 "Higher-grade managers and administrators" ///
10 "Lower-grade managers and administrators" ///
11 "Skilled clerks" ///
12 "Unskilled clerks" ///
13 "Socio-cultural professionals" ///
14 "Socio-cultural semi-professionals" ///
15 "Skilled service" ///
16 "Low-skilled service"
label value class16 class16
tab class16

recode class16 (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8), gen(class8)
label variable class8 "Final Oesch class position - 8 classes"
label define class8 ///
1 "Self-employed professionals and large employers" ///
2 "Small business owners" ///
3 "Technical (semi-)professionals" ///
4 "Production workers" ///
5 "(Associate) managers" ///
6 "Clerks" ///
7 "Socio-cultural (semi-)professionals" ///
8 "Service workers"
label value class8 class8
tab class8

recode class16 (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5), gen(class5)
label variable class5 "Final Oesch class position - 5 classes"
label define class5 ///
1 "Higher-grade service class" ///
2 "Lower-grade service class" ///
3 "Small business owners" ///
4 "Skilled workers" ///
5 "Unskilled workers"
label value class5 class5
tab class5


drop isco88_mainjob selfem_mainjob isco88_partner selfem_partner

	
*******************************************************************************
* SPECIFIC Oesch’s class schema for Great Britain 1987 
*******************************************************************************

*************************************************
* Create Oesch class schema for respondent
* Create GB87_class
* Using GB_OCC87 and SELFEMP
*************************************************

*Class schema for respondent

gen GB87_class=.

* Large employers (1)
replace GB87_class=1 if SELFEMP==1 & GB_OCC87==3
replace GB87_class=1 if SELFEMP==1 & GB_OCC87==5
replace GB87_class=1 if SELFEMP==1 & GB_OCC87==7
replace GB87_class=1 if SELFEMP==1 & GB_OCC87==9
replace GB87_class=1 if SELFEMP==1 & GB_OCC87==34
replace GB87_class=1 if SELFEMP==1 & GB_OCC87==36
replace GB87_class=1 if SELFEMP==1 & GB_OCC87==38
replace GB87_class=1 if SELFEMP==1 & GB_OCC87==44


****NB: no good differenciation possible between (1) and (3)

* Self-employed professionals (2)
replace GB87_class=2 if SELFEMP==1 & GB_OCC87==1
replace GB87_class=2 if SELFEMP==1 & GB_OCC87==2
replace GB87_class=2 if SELFEMP==1 & GB_OCC87==4
replace GB87_class=2 if SELFEMP==1 & GB_OCC87>=10 & GB_OCC87<=21 
replace GB87_class=2 if SELFEMP==1 & GB_OCC87>=24 & GB_OCC87<=33


* Small business owners with employees (3)
replace GB87_class=3 if SELFEMP==1 & GB_OCC87==35
replace GB87_class=3 if SELFEMP==1 & GB_OCC87==37
replace GB87_class=3 if SELFEMP==1 & GB_OCC87==39

* Small business owners without employees (4)
replace GB87_class=4 if SELFEMP==1 & GB_OCC87==6
replace GB87_class=4 if SELFEMP==1 & GB_OCC87==22
replace GB87_class=4 if SELFEMP==1 & GB_OCC87==32
replace GB87_class=4 if SELFEMP==1 & GB_OCC87==40
replace GB87_class=4 if SELFEMP==1 & GB_OCC87==43
replace GB87_class=4 if SELFEMP==1 & GB_OCC87>=45 & GB_OCC87<=998

* Technical experts (5)
replace GB87_class=5 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==4
replace GB87_class=5 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=24 & GB_OCC87<=28
replace GB87_class=5 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==30
replace GB87_class=5 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==31
replace GB87_class=5 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==33

* Technicians (6)
replace GB87_class=6 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==6
replace GB87_class=6 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==22
replace GB87_class=6 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==32

* Skilled manual (7)
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==63
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==76
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==78
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==79
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==85
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==87
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=90 & GB_OCC87<=95
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==102
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==111
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==114
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==115
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=118 & GB_OCC87<=128
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==130
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==132
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==133
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==139
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==140
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==143
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==998

* Low-skilled manual (8)

replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==40
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==77
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==80
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==83
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==89
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=97 & GB_OCC87<=101
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=105 & GB_OCC8<=110
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==112
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==113
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==117
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==129
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==131
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=134 & GB_OCC87<=138
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==141
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=144 & GB_OCC87<=161

* Higher-grade managers and administrators (9)

replace GB87_class=9 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=1 & GB_OCC87<=3
replace GB87_class=9 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==5
replace GB87_class=9 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==7
replace GB87_class=9 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==9
replace GB87_class=9 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=34 & GB_OCC87<=36
replace GB87_class=9 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==44

* Lower-grade managers and administrators (10)

replace GB87_class=10 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=37 & GB_OCC87<=39
replace GB87_class=10 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==57
replace GB87_class=10 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==60


***NB: no good differenciation possible between (9) and (10) for manager of "small" entreprises


* Skilled clerks (11)
replace GB87_class=11 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=45 & GB_OCC87<=46
replace GB87_class=11 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=48 & GB_OCC87<=50
replace GB87_class=11 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=53 & GB_OCC87<=54

* Unskilled clerks (12)

replace GB87_class=12 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==51
replace GB87_class=12 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==47


* Socio-cultural professionals (13)

replace GB87_class=13 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=10 & GB_OCC87<=11
replace GB87_class=13 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=13 & GB_OCC87<=19


* Socio-cultural semi-professionals (14)

replace GB87_class=14 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==12
replace GB87_class=14 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==20
replace GB87_class=14 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==21
replace GB87_class=14 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==29

* Skilled service (15)

replace GB87_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==43
replace GB87_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==55
replace GB87_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==56
replace GB87_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==61
replace GB87_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==62
replace GB87_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==64
replace GB87_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==74


* Low-skilled service (16)
replace GB87_class=16 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=65 & GB_OCC87<=72
replace GB87_class=16 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==75


* Not classifiable (0): military + "other occupation"

replace GB87_class=0 if GB_OCC87==41
replace GB87_class=0 if GB_OCC87==458

replace GB87_class=. if GB_OCC87==.i
replace GB87_class=. if GB_OCC87==.n


tab GB87_class if COUNTRY==82601 & YEAR==1987, m


*************************************************
* Create Oesch class schema for partner
* Create GB87_pclass
* Using GB_SOCC87 and SPSELFEM
*************************************************

gen GB87_pclass=.

* Large employers (1)
replace GB87_pclass=1 if SPSELFEM==1 & GB_SOC87==3
replace GB87_pclass=1 if SPSELFEM==1 & GB_SOC87==5
replace GB87_pclass=1 if SPSELFEM==1 & GB_SOC87==7
replace GB87_pclass=1 if SPSELFEM==1 & GB_SOC87==9
replace GB87_pclass=1 if SPSELFEM==1 & GB_SOC87==34
replace GB87_pclass=1 if SPSELFEM==1 & GB_SOC87==36
replace GB87_pclass=1 if SPSELFEM==1 & GB_SOC87==38
replace GB87_pclass=1 if SPSELFEM==1 & GB_SOC87==44


****NB: no good differenciation possible between (1) and (3)

* Self-employed professionals (2)
replace GB87_pclass=2 if SPSELFEM==1 & GB_SOC87==1
replace GB87_pclass=2 if SPSELFEM==1 & GB_SOC87==2
replace GB87_pclass=2 if SPSELFEM==1 & GB_SOC87==4
replace GB87_pclass=2 if SPSELFEM==1 & GB_SOC87>=10 & GB_SOC87<=21 
replace GB87_pclass=2 if SPSELFEM==1 & GB_SOC87>=24 & GB_SOC87<=33


* Small business owners with employees (3)
replace GB87_pclass=3 if SPSELFEM==1 & GB_SOC87==35
replace GB87_pclass=3 if SPSELFEM==1 & GB_SOC87==37
replace GB87_pclass=3 if SPSELFEM==1 & GB_SOC87==39

* Small business owners without employees (4)
replace GB87_pclass=4 if SPSELFEM==1 & GB_SOC87==6
replace GB87_pclass=4 if SPSELFEM==1 & GB_SOC87==22
replace GB87_pclass=4 if SPSELFEM==1 & GB_SOC87==32
replace GB87_pclass=4 if SPSELFEM==1 & GB_SOC87==40
replace GB87_pclass=4 if SPSELFEM==1 & GB_SOC87==43
replace GB87_pclass=4 if SPSELFEM==1 & GB_SOC87>=45 & GB_SOC87<=998

* Technical experts (5)
replace GB87_pclass=5 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==4
replace GB87_pclass=5 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87>=24 & GB_SOC87<=28
replace GB87_pclass=5 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==30
replace GB87_pclass=5 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==31
replace GB87_pclass=5 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==33

* Technicians (6)
replace GB87_pclass=6 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==6
replace GB87_pclass=6 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==22
replace GB87_pclass=6 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==32

* Skilled manual (7)
replace GB87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==63
replace GB87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==76
replace GB87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==78
replace GB87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==79
replace GB87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==85
replace GB87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==87
replace GB87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87>=90 & GB_SOC87<=95
replace GB87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==102
replace GB87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==111
replace GB87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==114
replace GB87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==115
replace GB87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87>=118 & GB_SOC87<=128
replace GB87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==130
replace GB87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==132
replace GB87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==133
replace GB87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==139
replace GB87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==140
replace GB87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==143
replace GB87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==998

* Low-skilled manual (8)

replace GB87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==40
replace GB87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==77
replace GB87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==80
replace GB87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==83
replace GB87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==89
replace GB87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87>=97 & GB_SOC87<=101
replace GB87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87>=105 & GB_OCC8<=110
replace GB87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==112
replace GB87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==113
replace GB87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==117
replace GB87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==129
replace GB87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==131
replace GB87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87>=134 & GB_SOC87<=138
replace GB87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==141
replace GB87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87>=144 & GB_SOC87<=161

* Higher-grade managers and administrators (9)

replace GB87_pclass=9 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87>=1 & GB_SOC87<=3
replace GB87_pclass=9 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==5
replace GB87_pclass=9 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==7
replace GB87_pclass=9 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==9
replace GB87_pclass=9 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87>=34 & GB_SOC87<=36
replace GB87_pclass=9 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==44

* Lower-grade managers and administrators (10)

replace GB87_pclass=10 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87>=37 & GB_SOC87<=39
replace GB87_pclass=10 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==57
replace GB87_pclass=10 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==60


****NB: no good differenciation possible between (9) and (10) fpr manager of "small" entreprises


* Skilled clerks (11)
replace GB87_pclass=11 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87>=45 & GB_SOC87<=46
replace GB87_pclass=11 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87>=48 & GB_SOC87<=50
replace GB87_pclass=11 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87>=53 & GB_SOC87<=54

* Unskilled clerks (12)

replace GB87_pclass=12 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==51
replace GB87_pclass=12 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==47

* Socio-cultural professionals (13)

replace GB87_pclass=13 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87>=10 & GB_SOC87<=10
replace GB87_pclass=13 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87>=14 & GB_SOC87<=19
replace GB87_pclass=13 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==11

* Socio-cultural semi-professionals (14)
replace GB87_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==12
replace GB87_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==13
replace GB87_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==20
replace GB87_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==21
replace GB87_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==29

* Skilled service (15)

replace GB87_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==43
replace GB87_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==55
replace GB87_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==56
replace GB87_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==61
replace GB87_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==62
replace GB87_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==64
replace GB87_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==74


* Low-skilled service (16)
replace GB87_pclass=16 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87>=65 & GB_SOC87<=72
replace GB87_pclass=16 if (SPSELFEM==2 | SPSELFEM==.a) & GB_SOC87==75


* Not classifiable (0): military + "other occupation"

replace GB87_pclass=0 if GB_SOC87==41
replace GB87_pclass=0 if GB_SOC87==458

replace GB87_pclass=. if GB_SOC87==.i
replace GB87_pclass=. if GB_SOC87==.n


tab GB87_pclass if COUNTRY==82601 & YEAR==1987, m


*********************************************************
* Recode class16_r, class16_p, class8_r, class8_p, class5_r, class5_p
* Recode class16, class8, class5
* for Great Britain 1987
*********************************************************

replace class16_r=GB87_class if COUNTRY==82601 & YEAR==1987
replace class16_p=GB87_pclass if COUNTRY==82601 & YEAR==1987

recode class16_r (0=.)
recode class16_p (0=.)


replace class8_r=class16_r if COUNTRY==82601 & YEAR==1987
recode class8_r (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8) if COUNTRY==82601 & YEAR==1987

replace class8_p=class16_p if COUNTRY==82601 & YEAR==1987
recode class8_p (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8) if COUNTRY==82601 & YEAR==1987


replace class5_r=class16_r if COUNTRY==82601 & YEAR==1987
recode class5_r (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5) if COUNTRY==82601 & YEAR==1987

replace class5_p=class16_p if COUNTRY==82601 & YEAR==1987
recode class5_p (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5) if COUNTRY==82601 & YEAR==1987


replace class16=class16_r if COUNTRY==82601 & YEAR==1987
replace class16=class16_p if class16_r==. & COUNTRY==82601 & YEAR==1987

replace class8=class16 if COUNTRY==82601 & YEAR==1987
recode class8 (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8) if COUNTRY==82601 & YEAR==1987

replace class5=class16 if COUNTRY==82601 & YEAR==1987
recode class5 (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5) if COUNTRY==82601 & YEAR==1987


*******************************************************************************
* SPECIFIC Oesch’s class schema for Great Britain 1992 
*******************************************************************************

*************************************************
* Create Oesch class schema for respondent
* Create GB92_class
* Using GB_OCC92 and SELFEMP
*************************************************

***CLASSES FOR GB 1992
gen GB92_class=.

* Large employers (1)
replace GB92_class=1 if SELFEMP==1 & GB_OCC92>=10 & GB_OCC92<=19

***NB: no good differenciation possible between (1) and (3)

* Self-employed professionals (2)
replace GB92_class=2 if SELFEMP==1 & GB_OCC92>=20 & GB_OCC92<=29
replace GB92_class=2 if SELFEMP==1 & GB_OCC92>=31 & GB_OCC92<=32
replace GB92_class=2 if SELFEMP==1 & GB_OCC92>=34 & GB_OCC92<=37

* Small business owners with employees (3)
replace GB92_class=3 if SELFEMP==1 & GB_OCC92==94

* Small business owners without employees (4)
replace GB92_class=4 if SELFEMP==1 & GB_OCC92==30
replace GB92_class=4 if SELFEMP==1 & GB_OCC92==33
replace GB92_class=4 if SELFEMP==1 & GB_OCC92>=38 & GB_OCC92<=93
replace GB92_class=4 if SELFEMP==1 & GB_OCC92==95

* Technical experts (5)
replace GB92_class=5 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=20 & GB_OCC92<=21
replace GB92_class=5 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==26

* Technicians (6)
replace GB92_class=6 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==30
replace GB92_class=6 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==33

* Skilled manual (7)
replace GB92_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=50 & GB_OCC92<=59
replace GB92_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==80
replace GB92_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==90

* Low-skilled manual (8)

replace GB92_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=81 & GB_OCC92<=89
replace GB92_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=91 & GB_OCC92<=93

* Higher-grade managers and administrators (9)

replace GB92_class=9 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=10 & GB_OCC92<=19
replace GB92_class=9 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=24 & GB_OCC92<=25
replace GB92_class=9 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==29
replace GB92_class=9 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=31 & GB_OCC92<=32
replace GB92_class=9 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=35 & GB_OCC92<=36

* Lower-grade managers and administrators (10)

replace GB92_class=10 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==39
replace GB92_class=10 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==94
replace GB92_class=10 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==15
replace GB92_class=10 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==70
replace GB92_class=10 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==71
replace GB92_class=10 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==94

****NB: no good differenciation possible between (9) and (10) for manager of "small" entreprises

* Skilled clerks (11)
replace GB92_class=11 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==40
replace GB92_class=11 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=42 & GB_OCC92<=45
replace GB92_class=11 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=47 & GB_OCC92<=49


* Unskilled clerks (12)

replace GB92_class=12 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==41
replace GB92_class=12 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==46


* Socio-cultural professionals (13)

replace GB92_class=13 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=22 & GB_OCC92<=23
replace GB92_class=13 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==27
replace GB92_class=13 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==34
replace GB92_class=13 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==64

* Socio-cultural semi-professionals (14)

replace GB92_class=14 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=37 & GB_OCC92<=38
replace GB92_class=14 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=22 & GB_OCC92<=23

* Skilled service (15)

replace GB92_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==61
replace GB92_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==63
replace GB92_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==69
replace GB92_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=65 & GB_OCC92<=66
replace GB92_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=72 & GB_OCC92<=79
replace GB92_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==95

* Low-skilled service (16)
replace GB92_class=16 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==62
replace GB92_class=16 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==67

* Not classifiable (0): military + "other occupation"

replace GB92_class=0 if GB_OCC92==99
replace GB92_class=0 if GB_OCC92==60

replace GB92_class=. if GB_OCC92==.n


tab GB92_class if COUNTRY==82601 & YEAR==1992, m


*************************************************
* Create Oesch class schema for partner
* Create GB92_pclass
* Using GB_SOCC92 and SPSELFEM
*************************************************

gen GB92_pclass=.

* Large employers (1)
replace GB92_pclass=1 if SPSELFEM==1 & GB_SOC92>=10 & GB_SOC92<=19

****NB: no good differenciation possible between (1) and (3)

* Self-employed professionals (2)
replace GB92_pclass=2 if SPSELFEM==1 & GB_SOC92>=20 & GB_SOC92<=29
replace GB92_pclass=2 if SPSELFEM==1 & GB_SOC92>=31 & GB_SOC92<=32
replace GB92_pclass=2 if SPSELFEM==1 & GB_SOC92>=34 & GB_SOC92<=37

* Small business owners with employees (3)
replace GB92_pclass=3 if SPSELFEM==1 & GB_SOC92==94

* Small business owners without employees (4)
replace GB92_pclass=4 if SPSELFEM==1 & GB_SOC92==30
replace GB92_pclass=4 if SPSELFEM==1 & GB_SOC92==33
replace GB92_pclass=4 if SPSELFEM==1 & GB_SOC92>=38 & GB_SOC92<=93
replace GB92_pclass=4 if SPSELFEM==1 & GB_SOC92==95

* Technical experts (5)
replace GB92_pclass=5 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92>=20 & GB_SOC92<=21
replace GB92_pclass=5 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92==26

* Technicians (6)
replace GB92_pclass=6 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92==30
replace GB92_pclass=6 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92==33

* Skilled manual (7)
replace GB92_pclass=7 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92>=50 & GB_SOC92<=59
replace GB92_pclass=7 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92==80
replace GB92_pclass=7 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92==90

* Low-skilled manual (8)

replace GB92_pclass=8 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92>=81 & GB_SOC92<=89
replace GB92_pclass=8 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92>=91 & GB_SOC92<=93

* Higher-grade managers and administrators (9)

replace GB92_pclass=9 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92>=10 & GB_SOC92<=19
replace GB92_pclass=9 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92>=24 & GB_SOC92<=25
replace GB92_pclass=9 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92==29
replace GB92_pclass=9 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92>=31 & GB_SOC92<=32
replace GB92_pclass=9 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92>=35 & GB_SOC92<=36

* Lower-grade managers and administrators (10)

replace GB92_pclass=10 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92==39
replace GB92_pclass=10 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92==94
replace GB92_pclass=10 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92==15
replace GB92_pclass=10 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92==70
replace GB92_pclass=10 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92==71
replace GB92_pclass=10 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92==94

****NB: no good differenciation possible between (9) and (10) fpr manager of "small" entreprises

* Skilled clerks (11)
replace GB92_pclass=11 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92==40
replace GB92_pclass=11 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92>=42 & GB_SOC92<=45
replace GB92_pclass=11 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92>=47 & GB_SOC92<=49

* Unskilled clerks (12)

replace GB92_pclass=12 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92==41
replace GB92_pclass=12 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92==46

* Socio-cultural professionals (13)

replace GB92_pclass=13 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92>=22 & GB_SOC92<=23
replace GB92_pclass=13 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92==27
replace GB92_pclass=13 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92==34
replace GB92_pclass=13 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92==64

* Socio-cultural semi-professionals (14)

replace GB92_pclass=14 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92>=37 & GB_SOC92<=38
replace GB92_pclass=14 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92>=22 & GB_SOC92<=23

* Skilled service (15)

replace GB92_pclass=15 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92==61
replace GB92_pclass=15 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92==63
replace GB92_pclass=15 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92==69
replace GB92_pclass=15 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92>=65 & GB_SOC92<=66
replace GB92_pclass=15 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92>=72 & GB_SOC92<=79
replace GB92_pclass=15 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92==95

* Low-skilled service (16)
replace GB92_pclass=16 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92==62
replace GB92_pclass=16 if SPSELFEM==2 | SPSELFEM==.a & GB_SOC92==67


* Not classifiable (0): military + "other occupation"

replace GB92_pclass=. if GB_SOC92==99
replace GB92_pclass=. if GB_SOC92==60

replace GB92_pclass=. if GB_SOC92==.n


tab GB92_pclass if COUNTRY==82601 & YEAR==1992, m


*********************************************************
* Recode class16_r, class16_p, class8_r, class8_p, class5_r, class5_p
* Recode class16, class8, class5
* for Great Britain 1992
*********************************************************

replace class16_r=GB92_class if COUNTRY==82601 & YEAR==1992
replace class16_p=GB92_pclass if COUNTRY==82601 & YEAR==1992
recode class16_r (0=.)
recode class16_p (0=.)

replace class8_r=class16_r if COUNTRY==82601 & YEAR==1992
recode class8_r (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8) if COUNTRY==82601 & YEAR==1992

replace class8_p=class16_p if COUNTRY==82601 & YEAR==1992
recode class8_p (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8) if COUNTRY==82601 & YEAR==1992


replace class5_r=class16_r if COUNTRY==82601 & YEAR==1992
recode class5_r (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5) if COUNTRY==82601 & YEAR==1992

replace class5_p=class16_p if COUNTRY==82601 & YEAR==1992
recode class5_p (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5) if COUNTRY==82601 & YEAR==1992

replace class16=class16_r if COUNTRY==82601 & YEAR==1992
replace class16=class16_p if class16_r==. & COUNTRY==82601 & YEAR==1992

replace class8=class16 if COUNTRY==82601 & YEAR==1992
recode class8 (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8) if COUNTRY==82601 & YEAR==1992

replace class5=class16 if COUNTRY==82601 & YEAR==1992
recode class5 (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5) if COUNTRY==82601 & YEAR==1992



*******************************************************************************
* SPECIFIC Oesch’s class schema for Sweden 1992 
*******************************************************************************

*************************************************
* Create Oesch class schema for respondent
* Create SE92_class
* Using SE_OCC92 and SELFEMP
*************************************************

gen SE92_class=.

* Large employers (1)
replace SE92_class=1 if SELFEMP==1 & SE_OCC92==221
replace SE92_class=1 if SELFEMP==1 & SE_OCC92==232

****NB: no good differenciation possible between (1) and (3)

* Self-employed professionals (2)
replace SE92_class=2 if SELFEMP==1 & SE_OCC92
replace SE92_class=2 if SELFEMP==1 & SE_OCC92>=1 & SE_OCC92<=8
replace SE92_class=2 if SELFEMP==1 & SE_OCC92>=15 & SE_OCC92<=71
replace SE92_class=2 if SELFEMP==1 & SE_OCC92>=76 & SE_OCC92<=104
replace SE92_class=2 if SELFEMP==1 & SE_OCC92>=106 & SE_OCC92<=131
replace SE92_class=2 if SELFEMP==1 & SE_OCC92==155
replace SE92_class=2 if SELFEMP==1 & SE_OCC92==191
replace SE92_class=2 if SELFEMP==1 & SE_OCC92==219
replace SE92_class=2 if SELFEMP==1 & SE_OCC92>=251 & SE_OCC92<=261

* Small business owners with employees (3)
replace SE92_class=3 if SELFEMP==1 & SE_OCC92==152
replace SE92_class=3 if SELFEMP==1 & SE_OCC92>=201 & SE_OCC92<=212
replace SE92_class=3 if SELFEMP==1 & SE_OCC92==297
replace SE92_class=3 if SE_OCC92==331
replace SE92_class=3 if SE_OCC92==400
replace SE92_class=3 if SELFEMP==1 & SE_OCC92==404

* Small business owners without employees (4)
replace SE92_class=4 if SELFEMP==1 & SE_OCC92>=9 & SE_OCC92<=13
replace SE92_class=4 if SELFEMP==1 & SE_OCC92==74
replace SE92_class=4 if SELFEMP==1 & SE_OCC92==105
replace SE92_class=4 if SELFEMP==1 & SE_OCC92==139
replace SE92_class=4 if SELFEMP==1 & SE_OCC92==151
replace SE92_class=4 if SELFEMP==1 & SE_OCC92==154
replace SE92_class=4 if SELFEMP==1 & SE_OCC92>=159 & SE_OCC92<=169
replace SE92_class=4 if SELFEMP==1 & SE_OCC92>=241 & SE_OCC92<=249
replace SE92_class=4 if SELFEMP==1 & SE_OCC92>=291 & SE_OCC92<=296
replace SE92_class=4 if SELFEMP==1 & SE_OCC92>=299 & SE_OCC92<=321
replace SE92_class=4 if SELFEMP==1 & SE_OCC92>=332 & SE_OCC92<=339
replace SE92_class=4 if SELFEMP==411 & SE_OCC92>=9 & SE_OCC92<=981

* Technical experts (5)
replace SE92_class=5 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=1 & SE_OCC92<=8
replace SE92_class=5 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=15 & SE_OCC92<=22
replace SE92_class=5 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==101
replace SE92_class=5 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==251
replace SE92_class=5 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==252

* Technicians (6)
replace SE92_class=6 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=9 & SE_OCC92<=13
replace SE92_class=6 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==74
replace SE92_class=6 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==105
replace SE92_class=6 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==162
replace SE92_class=6 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==231
replace SE92_class=6 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==621

* Skilled manual (7)
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==412
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==441
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==611
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==631
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==641
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==652
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==716
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==741
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==744
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==752
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==754
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==755
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==756
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==761
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==764
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==765
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=781 & SE_OCC92<=796
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==801
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==802
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==805
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=819 & SE_OCC92<=829
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==661
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==661
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==912

* Low-skilled manual (8)
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==411
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==413
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==414
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==664
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==669
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=733 & SE_OCC92<=739
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==749
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==751
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==753
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==759
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==763
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==772
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==777
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==799
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==803
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==809
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=831 & SE_OCC92<=882

* Higher-grade managers and administrators (9)
replace SE92_class=9 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==53
replace SE92_class=9 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==152
replace SE92_class=9 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=201 & SE_OCC92<=203
replace SE92_class=9 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=212 & SE_OCC92<=222
replace SE92_class=9 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==232
replace SE92_class=9 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==261
replace SE92_class=9 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==299
replace SE92_class=9 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==311
replace SE92_class=9 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==404

* Lower-grade managers and administrators (10)
replace SE92_class=10 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==211
replace SE92_class=10 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==293
replace SE92_class=10 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==294
replace SE92_class=10 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==297
replace SE92_class=10 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==312
replace SE92_class=10 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==313
replace SE92_class=10 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==321
replace SE92_class=10 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==332

****NB: no good differenciation possible between (9) and (10) fpr manager of "small" entreprises

* Skilled clerks (11)
replace SE92_class=11 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==241
replace SE92_class=11 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==242
replace SE92_class=11 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==249
replace SE92_class=11 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==291
replace SE92_class=11 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==292
replace SE92_class=11 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==295
replace SE92_class=11 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==296
replace SE92_class=11 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==671
replace SE92_class=11 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==673
replace SE92_class=11 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==681
replace SE92_class=11 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==904

* Unskilled clerks (12)
replace SE92_class=12 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==674

* Socio-cultural professionals (13)
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=30 & SE_OCC92<=32
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==34
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==35
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==37
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==41
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==61
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==103
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==104
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=106 & SE_OCC92<=121
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==131
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==153
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==155
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==191

* Socio-cultural semi-professionals (14)
replace SE92_class=14 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==33
replace SE92_class=14 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==36
replace SE92_class=14 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==39
replace SE92_class=14 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==49
replace SE92_class=14 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==71
replace SE92_class=14 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=76 & SE_OCC92<=79
replace SE92_class=14 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==151
replace SE92_class=14 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==159
replace SE92_class=14 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==169

* Skilled service (15)
replace SE92_class=15 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==123
replace SE92_class=15 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==139
replace SE92_class=15 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==333
replace SE92_class=15 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==339
replace SE92_class=15 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==640
replace SE92_class=15 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==642
replace SE92_class=15 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=901 & SE_OCC92<=903
replace SE92_class=15 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==911
replace SE92_class=15 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==941

* Low-skilled service (16)
replace SE92_class=16 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==154
replace SE92_class=16 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==682
replace SE92_class=16 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=913 & SE_OCC92<=932

* Not classifiable (0): military + "other occupation"

replace SE92_class=0 if SE_OCC92==981
replace SE92_class=. if SE_OCC92==.i


tab SE92_class if COUNTRY==752 & YEAR==1992, m


*************************************************
* Create Oesch class schema for partner
* Create SE92_pclass
* Using SE_SOC92 and SPSELFEM
*************************************************

gen SE92_pclass=.

* Large employers (1)
replace SE92_pclass=1 if SPSELFEM==1 & SE_SOC92==221
replace SE92_pclass=1 if SPSELFEM==1 & SE_SOC92==232

****NB: no good differenciation possible between (1) and (3)

* Self-employed professionals (2)
replace SE92_pclass=2 if SPSELFEM==1 & SE_SOC92>=1 & SE_SOC92<=8
replace SE92_pclass=2 if SPSELFEM==1 & SE_SOC92>=15 & SE_SOC92<=71
replace SE92_pclass=2 if SPSELFEM==1 & SE_SOC92>=76 & SE_SOC92<=104
replace SE92_pclass=2 if SPSELFEM==1 & SE_SOC92>=106 & SE_SOC92<=131
replace SE92_pclass=2 if SPSELFEM==1 & SE_SOC92==155
replace SE92_pclass=2 if SPSELFEM==1 & SE_SOC92==191
replace SE92_pclass=2 if SPSELFEM==1 & SE_SOC92==219
replace SE92_pclass=2 if SPSELFEM==1 & SE_SOC92==229
replace SE92_pclass=2 if SPSELFEM==1 & SE_SOC92>=251 & SE_SOC92<=261

* Small business owners with employees (3)
replace SE92_pclass=3 if SPSELFEM==1 & SE_SOC92==152
replace SE92_pclass=3 if SPSELFEM==1 & SE_SOC92>=201 & SE_SOC92<=212
replace SE92_pclass=3 if SPSELFEM==1 & SE_SOC92==297
replace SE92_pclass=3 if SE_SOC92==331
replace SE92_pclass=3 if SE_SOC92==400
replace SE92_pclass=3 if SPSELFEM==1 & SE_SOC92==404

* Small business owners without employees (4)
replace SE92_pclass=4 if SPSELFEM==1 & SE_SOC92>=9 & SE_SOC92<=13
replace SE92_pclass=4 if SPSELFEM==1 & SE_SOC92==73
replace SE92_pclass=4 if SPSELFEM==1 & SE_SOC92==74
replace SE92_pclass=4 if SPSELFEM==1 & SE_SOC92==105
replace SE92_pclass=4 if SPSELFEM==1 & SE_SOC92==139
replace SE92_pclass=4 if SPSELFEM==1 & SE_SOC92==151
replace SE92_pclass=4 if SPSELFEM==1 & SE_SOC92==154
replace SE92_pclass=4 if SPSELFEM==1 & SE_SOC92>=159 & SE_SOC92<=169
replace SE92_pclass=4 if SPSELFEM==1 & SE_SOC92==192
replace SE92_pclass=4 if SPSELFEM==1 & SE_SOC92==199
replace SE92_pclass=4 if SPSELFEM==1 & SE_SOC92==239
replace SE92_pclass=4 if SPSELFEM==1 & SE_SOC92>=241 & SE_SOC92<=249
replace SE92_pclass=4 if SPSELFEM==1 & SE_SOC92==259
replace SE92_pclass=4 if SPSELFEM==1 & SE_SOC92>=291 & SE_SOC92<=296
replace SE92_pclass=4 if SPSELFEM==1 & SE_SOC92>=299 & SE_SOC92<=321
replace SE92_pclass=4 if SPSELFEM==1 & SE_SOC92>=332 & SE_SOC92<=339
replace SE92_pclass=4 if SPSELFEM==1 & SE_SOC92==401
replace SE92_pclass=4 if SPSELFEM==411 & SE_SOC92>=411 & SE_SOC92<=981

* Technical experts (5)
replace SE92_pclass=5 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92>=1 & SE_SOC92<=8
replace SE92_pclass=5 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92>=15 & SE_SOC92<=22
replace SE92_pclass=5 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==101
replace SE92_pclass=5 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==251
replace SE92_pclass=5 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==252

* Technicians (6)
replace SE92_pclass=6 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92>=9 & SE_SOC92<=13
replace SE92_pclass=6 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==74
replace SE92_pclass=6 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==105
replace SE92_pclass=6 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==162
replace SE92_pclass=6 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==231
replace SE92_pclass=6 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==259
replace SE92_pclass=6 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==621

* Skilled manual (7)
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==401
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==412
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==441
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==501
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==509
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==611
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==631
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==641
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==652
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==716
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==741
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==744
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==752
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==754
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==755
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==756
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==761
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==764
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==765
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92>=781 & SE_SOC92<=796
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==801
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==802
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==805
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92>=819 & SE_SOC92<=829
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==661
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==661
replace SE92_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==912

* Low-skilled manual (8)
replace SE92_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==411
replace SE92_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==413
replace SE92_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==414
replace SE92_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==664
replace SE92_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==669
replace SE92_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92>=733 & SE_SOC92<=739
replace SE92_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==749
replace SE92_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==751
replace SE92_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==753
replace SE92_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==759
replace SE92_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==763
replace SE92_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==772
replace SE92_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==777
replace SE92_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==799
replace SE92_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==803
replace SE92_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==809
replace SE92_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92>=831 & SE_SOC92<=882

* Higher-grade managers and administrators (9)
replace SE92_pclass=9 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==53
replace SE92_pclass=9 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==102
replace SE92_pclass=9 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==152
replace SE92_pclass=9 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92>=201 & SE_SOC92<=203
replace SE92_pclass=9 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92>=212 & SE_SOC92<=222
replace SE92_pclass=9 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==229
replace SE92_pclass=9 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==232
replace SE92_pclass=9 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==261
replace SE92_pclass=9 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==299
replace SE92_pclass=9 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==311
replace SE92_pclass=9 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==404

* Lower-grade managers and administrators (10)
replace SE92_pclass=10 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==211
replace SE92_pclass=10 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==293
replace SE92_pclass=10 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==294
replace SE92_pclass=10 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==297
replace SE92_pclass=10 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==312
replace SE92_pclass=10 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==313
replace SE92_pclass=10 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==319
replace SE92_pclass=10 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==321
replace SE92_pclass=10 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==332



****NB: no good differenciation possible between (9) and (10) fpr manager of "small" entreprises


* Skilled clerks (11)
replace SE92_pclass=11 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==239
replace SE92_pclass=11 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==241
replace SE92_pclass=11 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==242
replace SE92_pclass=11 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==249
replace SE92_pclass=11 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==291
replace SE92_pclass=11 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==292
replace SE92_pclass=11 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==295
replace SE92_pclass=11 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==296
replace SE92_pclass=11 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==671
replace SE92_pclass=11 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==673
replace SE92_pclass=11 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==681
replace SE92_pclass=11 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==904

* Unskilled clerks (12)
replace SE92_pclass=12 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==674

* Socio-cultural professionals (13)
replace SE92_pclass=13 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92>=30 & SE_SOC92<=32
replace SE92_pclass=13 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==34
replace SE92_pclass=13 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==35
replace SE92_pclass=13 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==37
replace SE92_pclass=13 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==41
replace SE92_pclass=13 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==61
replace SE92_pclass=13 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==63
replace SE92_pclass=13 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==91
replace SE92_pclass=13 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==103
replace SE92_pclass=13 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==104
replace SE92_pclass=13 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92>=106 & SE_SOC92<=121
replace SE92_pclass=13 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==131
replace SE92_pclass=13 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==153
replace SE92_pclass=13 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==155
replace SE92_pclass=13 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==191

* Socio-cultural semi-professionals (14)
replace SE92_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==33
replace SE92_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==36
replace SE92_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==39
replace SE92_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==49
replace SE92_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==71
replace SE92_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==73
replace SE92_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92>=76 & SE_SOC92<=79
replace SE92_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==151
replace SE92_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==159
replace SE92_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==169
replace SE92_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==192
replace SE92_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==199

* Skilled service (15)
replace SE92_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==123
replace SE92_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==139
replace SE92_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==333
replace SE92_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==339
replace SE92_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==640
replace SE92_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==642
replace SE92_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92>=901 & SE_SOC92<=903
replace SE92_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==909
replace SE92_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==911
replace SE92_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==941

* Low-skilled service (16)
replace SE92_pclass=16 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==154
replace SE92_pclass=16 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==643
replace SE92_pclass=16 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92==682
replace SE92_pclass=16 if (SPSELFEM==2 | SPSELFEM==.a) & SE_SOC92>=913 & SE_SOC92<=932

* Not classifiable (0): military + "other occupation"

replace SE92_pclass=0 if SE_SOC92==981

replace SE92_pclass=. if SE_SOC92==.i
replace SE92_pclass=. if SE_SOC92==.w


tab SE92_pclass if COUNTRY==752 & YEAR==1992, m


*********************************************************
* Recode class16_r, class16_p, class8_r, class8_p, class5_r, class5_p
* Recode class16, class8, class5
* for Sweden 1992
*********************************************************

replace class16_r=SE92_class if COUNTRY==752 & YEAR==1992
replace class16_r=. if SE92_class==0 & COUNTRY==752 & YEAR==1992
replace class16_p=SE92_pclass if COUNTRY==752 & YEAR==1992
replace class16_p=. if SE92_pclass==0 & COUNTRY==752 & YEAR==1992

recode class16_r (0=.)
recode class16_p (0=.)

replace class8_r=class16_r if COUNTRY==752 & YEAR==1992
recode class8_r (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8) if COUNTRY==752 & YEAR==1992

replace class8_p=class16_p if COUNTRY==752 & YEAR==1992
recode class8_p (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8) if COUNTRY==752 & YEAR==1992


replace class5_r=class16_r if COUNTRY==752 & YEAR==1992
recode class5_r (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5) if COUNTRY==752 & YEAR==1992

replace class5_p=class16_p if COUNTRY==752 & YEAR==1992
recode class5_p (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5) if COUNTRY==752 & YEAR==1992


replace class16=class16_r if COUNTRY==752 & YEAR==1992
replace class16=class16_p if class16_r==. & COUNTRY==752 & YEAR==1992

replace class8=class16 if COUNTRY==752 & YEAR==1992
recode class8 (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8) if COUNTRY==752 & YEAR==1992

replace class5=class16 if COUNTRY==752 & YEAR==1992
recode class5 (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5) if COUNTRY==752 & YEAR==1992


*******************************************************************************
* SPECIFIC Oesch’s class schema for United States 1987
*******************************************************************************

*************************************************
* Create Oesch class schema for respondent
* Create US87_class
* Using US_OCC87 and SELFEMP
*************************************************

gen US87_class=.

* Large employers (1)
replace US87_class=1 if SELFEMP==1 & US_OCC87>=202 & US_OCC87<=224
replace US87_class=1 if SELFEMP==1 & US_OCC87>=231 & US_OCC87<=233

****NB: no good differenciation possible between (1) and (3)

* Self-employed professionals (2)
replace US87_class=2 if SELFEMP==1 & US_OCC87>=1 & US_OCC87<=65
replace US87_class=2 if SELFEMP==1 & US_OCC87>=91 & US_OCC87<=152
replace US87_class=2 if SELFEMP==1 & US_OCC87>=174 & US_OCC87<=201
replace US87_class=2 if SELFEMP==1 & US_OCC87>=240 & US_OCC87<=245

* Small business owners with employees (3)
replace US87_class=3 if SELFEMP==1 & US_OCC87==230
replace US87_class=3 if SELFEMP==1 & US_OCC87==801

* Small business owners without employees (4)
replace US87_class=4 if SELFEMP==1 & US_OCC87>=74 & US_OCC87<=90
replace US87_class=4 if SELFEMP==1 & US_OCC87>=153 & US_OCC87<=173
replace US87_class=4 if SELFEMP==1 & US_OCC87==225
replace US87_class=4 if SELFEMP==1 & US_OCC87>=260 & US_OCC87<=563
replace US87_class=4 if SELFEMP==1 & US_OCC87>=601 & US_OCC87<=785
replace US87_class=4 if SELFEMP==1 & US_OCC87>=822 & US_OCC87<=984

* Technical experts (5)
replace US87_class=5 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=1 & US_OCC87<=25

* Technicians (6)
replace US87_class=6 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=153 & US_OCC87<=173
replace US87_class=6 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==450
replace US87_class=6 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==452
replace US87_class=6 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==610

* Skilled manual (7)
replace US87_class=7 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=402 & US_OCC87<=446
replace US87_class=7 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=454 & US_OCC87<=563
replace US87_class=7 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=613 & US_OCC87<=620
replace US87_class=7 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==624
replace US87_class=7 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==645
replace US87_class=7 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==663
replace US87_class=7 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=671 & US_OCC87<=680
replace US87_class=7 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==740
replace US87_class=7 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==752
replace US87_class=7 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==755
replace US87_class=7 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==761
replace US87_class=7 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==763

* Low-skilled manual (8)
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=601 & US_OCC87<=612
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=622 & US_OCC87<=623
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=630 & US_OCC87<=643
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=650 & US_OCC87<=656
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==664
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=690 & US_OCC87<=695
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==706
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==715
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==751
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==753
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==760
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==762
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=764 & US_OCC87<=823

* Higher-grade managers and administrators (9)
replace US87_class=9 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==30
replace US87_class=9 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==31
replace US87_class=9 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==91
replace US87_class=9 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=201 & US_OCC87<=224
replace US87_class=9 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=230 & US_OCC87<=233
replace US87_class=9 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==245


* Lower-grade managers and administrators (10)
replace US87_class=10 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==225
replace US87_class=10 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==240
replace US87_class=10 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=265 & US_OCC87<=271
replace US87_class=10 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==305
replace US87_class=10 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==964
replace US87_class=10 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==965

* Skilled clerks (11)
replace US87_class=11 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==301
replace US87_class=11 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=310 & US_OCC87<=314
replace US87_class=11 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=320 & US_OCC87<=381
replace US87_class=11 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=391 & US_OCC87<=395

* Unskilled clerks (12)
replace US87_class=12 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==315
replace US87_class=12 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=384 & US_OCC87<=390

* Socio-cultural professionals (13)
replace US87_class=13 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=32 & US_OCC87<=65
replace US87_class=13 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==93
replace US87_class=13 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=110 & US_OCC87<=141
replace US87_class=13 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=144 & US_OCC87<=152
replace US87_class=13 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==174
replace US87_class=13 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==181
replace US87_class=13 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==184

* Socio-cultural semi-professionals (14)
replace US87_class=14 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=74 & US_OCC87<=90
replace US87_class=14 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==100
replace US87_class=14 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==142
replace US87_class=14 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==143
replace US87_class=14 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==175
replace US87_class=14 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==183
replace US87_class=14 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=185 & US_OCC87<=195
replace US87_class=14 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==382
replace US87_class=14 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==922
replace US87_class=14 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==924

* Skilled service (15)
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==226
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==260
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==262
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==280
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==640
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==703
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==912
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==921
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=925 & US_OCC87<=933
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==935
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==942
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==944
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=960 & US_OCC87<=962

* Low-skilled service (16)
replace US87_class=16 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==264
replace US87_class=16 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==705
replace US87_class=16 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==705
replace US87_class=16 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==714
replace US87_class=16  if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=901 & US_OCC87<=911
replace US87_class=16  if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=913 & US_OCC87<=916
replace US87_class=16 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==934
replace US87_class=16 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==940
replace US87_class=16 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==950
replace US87_class=16 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==952
replace US87_class=16  if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=980 & US_OCC87<=984

* Not classifiable (0): military + "other occupation"

replace US87_class=0 if US_OCC87==580
replace US87_class=0 if US_OCC87==590

replace US87_class=. if US_OCC87==.a
replace US87_class=. if US_OCC87==.c
replace US87_class=. if US_OCC87==.n


tab US87_class if COUNTRY==840 & YEAR==1987, m


*************************************************
* Create Oesch class schema for partner
* Create US87_pclass
* Using US_SOC87 and SPSELFEM
*************************************************

gen US87_pclass=.

* Large employers (1)
replace US87_pclass=1 if SPSELFEM==1 & US_SOC87>=202 & US_SOC87<=224
replace US87_pclass=1 if SPSELFEM==1 & US_SOC87>=231 & US_SOC87<=233

****NB: no good differenciation possible between (1) and (3)

* Self-employed professionals (2)
replace US87_pclass=2 if SPSELFEM==1 & US_SOC87>=1 & US_SOC87<=65
replace US87_pclass=2 if SPSELFEM==1 & US_SOC87>=91 & US_SOC87<=152
replace US87_pclass=2 if SPSELFEM==1 & US_SOC87>=174 & US_SOC87<=201
replace US87_pclass=2 if SPSELFEM==1 & US_SOC87>=240 & US_SOC87<=245

* Small business owners with employees (3)
replace US87_pclass=3 if SPSELFEM==1 & US_SOC87==230
replace US87_pclass=3 if SPSELFEM==1 & US_SOC87==801

* Small business owners without employees (4)
replace US87_pclass=4 if SPSELFEM==1 & US_SOC87>=74 & US_SOC87<=90
replace US87_pclass=4 if SPSELFEM==1 & US_SOC87>=153 & US_SOC87<=173
replace US87_pclass=4 if SPSELFEM==1 & US_SOC87==225
replace US87_pclass=4 if SPSELFEM==1 & US_SOC87>=260 & US_SOC87<=563
replace US87_pclass=4 if SPSELFEM==1 & US_SOC87>=260 & US_SOC87<=575
replace US87_pclass=4 if SPSELFEM==1 & US_SOC87>=601 & US_SOC87<=785
replace US87_pclass=4 if SPSELFEM==1 & US_SOC87>=822 & US_SOC87<=984

* Technical experts (5)
replace US87_pclass=5 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=1 & US_SOC87<=25

* Technicians (6)
replace US87_pclass=6 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=153 & US_SOC87<=173
replace US87_pclass=6 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==450
replace US87_pclass=6 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==452
replace US87_pclass=6 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==610

* Skilled manual (7)
replace US87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=402 & US_SOC87<=446
replace US87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=453 & US_SOC87<=563
replace US87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==575
replace US87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=613 & US_SOC87<=620
replace US87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==624
replace US87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==645
replace US87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==663
replace US87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=671 & US_SOC87<=680
replace US87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==740
replace US87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==752
replace US87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==755
replace US87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==761
replace US87_pclass=7 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==763

* Low-skilled manual (8)
replace US87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=601 & US_SOC87<=612
replace US87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=622 & US_SOC87<=623
replace US87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=630 & US_SOC87<=643
replace US87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=650 & US_SOC87<=656
replace US87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==681
replace US87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==664
replace US87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=690 & US_SOC87<=695
replace US87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==706
replace US87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==715
replace US87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==751
replace US87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==753
replace US87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==760
replace US87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==762
replace US87_pclass=8 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=764 & US_SOC87<=823

* Higher-grade managers and administrators (9)
replace US87_pclass=9 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==30
replace US87_pclass=9 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==31
replace US87_pclass=9 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==91
replace US87_pclass=9 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=201 & US_SOC87<=224
replace US87_pclass=9 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=230 & US_SOC87<=233
replace US87_pclass=9 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==245

* Lower-grade managers and administrators (10)
replace US87_pclass=10 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==225
replace US87_pclass=10 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==240
replace US87_pclass=10 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=265 & US_SOC87<=271
replace US87_pclass=10 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==305
replace US87_pclass=10 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==964
replace US87_pclass=10 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==965

* Skilled clerks (11)
replace US87_pclass=11 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==301
replace US87_pclass=11 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=310 & US_SOC87<=314
replace US87_pclass=11 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=320 & US_SOC87<=381
replace US87_pclass=11 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=391 & US_SOC87<=395

* Unskilled clerks (12)
replace US87_pclass=12 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==315
replace US87_pclass=12 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=384 & US_SOC87<=390

* Socio-cultural professionals (13)
replace US87_pclass=13 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=32 & US_SOC87<=65
replace US87_pclass=13 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==93
replace US87_pclass=13 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=110 & US_SOC87<=141
replace US87_pclass=13 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=144 & US_SOC87<=152
replace US87_pclass=13 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==174
replace US87_pclass=13 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==181
replace US87_pclass=13 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==184

* Socio-cultural semi-professionals (14)
replace US87_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=74 & US_SOC87<=90
replace US87_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==100
replace US87_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==101
replace US87_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==142
replace US87_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==143
replace US87_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==175
replace US87_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==183
replace US87_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=185 & US_SOC87<=195
replace US87_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==382
replace US87_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==922
replace US87_pclass=14 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==924

* Skilled service (15)
replace US87_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==226
replace US87_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==260
replace US87_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==262
replace US87_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==280
replace US87_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==640
replace US87_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==703
replace US87_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==912
replace US87_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==921
replace US87_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=925 & US_SOC87<=933
replace US87_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==935
replace US87_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==942
replace US87_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==944
replace US87_pclass=15 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=960 & US_SOC87<=962

* Low-skilled service (16)
replace US87_pclass=16 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==264
replace US87_pclass=16 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==705
replace US87_pclass=16 if US_SOC87==711
replace US87_pclass=16 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==714
replace US87_pclass=16  if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=901 & US_SOC87<=911
replace US87_pclass=16  if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=913 & US_SOC87<=916
replace US87_pclass=16 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==934
replace US87_pclass=16 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==940
replace US87_pclass=16 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==950
replace US87_pclass=16 if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87==952
replace US87_pclass=16  if (SPSELFEM==2 | SPSELFEM==.a) & US_SOC87>=980 & US_SOC87<=984

* Not classifiable (0): military + "other occupation"

replace US87_pclass=0 if US_SOC87==580
replace US87_pclass=0 if US_SOC87==590


replace US87_pclass=. if US_SOC87==.a
replace US87_pclass=. if US_SOC87==.c
replace US87_pclass=. if US_SOC87==.n


tab US87_pclass if COUNTRY==840 & YEAR==1987, m



*********************************************************
* Recode class16_r, class16_p, class8_r, class8_p, class5_r, class5_p
* Recode class16, class8, class5
* for United States 1987
*********************************************************

replace class16_r=US87_class if COUNTRY==840 & YEAR==1987
replace class16_p=US87_pclass if COUNTRY==840 & YEAR==1987

recode class16_r (0=.)
recode class16_p (0=.)


replace class8_r=class16_r if COUNTRY==840 & YEAR==1987
recode class8_r (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8) if COUNTRY==840 & YEAR==1987

replace class8_p=class16_p if COUNTRY==840 & YEAR==1987
recode class8_p (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8) if COUNTRY==840 & YEAR==1987


replace class5_r=class16_r if COUNTRY==840 & YEAR==1987
recode class5_r (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5) if COUNTRY==840 & YEAR==1987

replace class5_p=class16_p if COUNTRY==840 & YEAR==1987
recode class5_p (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5) if COUNTRY==840 & YEAR==1987


replace class16=class16_r if COUNTRY==840 & YEAR==1987
replace class16=class16_p if class16_r==. & COUNTRY==840 & YEAR==1987

replace class8=class16 if COUNTRY==840 & YEAR==1987
recode class8 (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8) if COUNTRY==840 & YEAR==1987

replace class5=class16 if COUNTRY==840 & YEAR==1987
recode class5 (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5) if COUNTRY==840 & YEAR==1987


*******************************************************************************
* SPECIFIC Oesch’s class schema for Poland 1987
* NB: Only 5-Class schema can be created + there are no partner information
* Recode class5
* Using PL_OCC87
*******************************************************************************

replace class5=1 if (PL_OCC87==1 | PL_OCC87==2) & COUNTRY==616 & YEAR==1987
replace class5=2 if (PL_OCC87==3) & COUNTRY==616 & YEAR==1987
replace class5=3 if (PL_OCC87==6 | PL_OCC87==11) & COUNTRY==616 & YEAR==1987 
replace class5=4 if (PL_OCC87==4 | PL_OCC87==5| PL_OCC87==7 |PL_OCC87==8) & COUNTRY==616 & YEAR==1987
replace class5=5 if (PL_OCC87==9 | PL_OCC87==10| PL_OCC87==12) & COUNTRY==616 & YEAR==1987


*******************************************************************************
* SPECIFIC Oesch’s class schema for ITALY 1987
* NB: Due to the lack of information, only 8-Class schema and 5-Class schema can be created
*******************************************************************************

*************************************************
* Create Oesch 8-Class schema for respondent
* Create IT87_class8
* Using IT_OCC87 and SELFEMP
*************************************************

gen IT87_class8=.

replace IT87_class8=1 if (IT_OCC87==11 | IT_OCC87==12 | IT_OCC87==14) & SELFEMP==1
replace IT87_class8=2 if (IT_OCC87==44 | IT_OCC87==43 | IT_OCC87==46) & SELFEMP==1
*NB1: no accurate distiction is possible between big business holder (IT87_class8=1) and small business holder (IT87_class8=2): all "Entrepreneurs, manufacturers" have been assigned to IT87_class8==1.
*NB2: No tecnical experts or tecnicians (IT87_class8=3) can be identified 

replace IT87_class8=4 if (IT_OCC87==31 | IT_OCC87==34 | IT_OCC87==43) & (SELFEMP==2 | SELFEMP==.)
replace IT87_class8=5 if (IT_OCC87==21 | IT_OCC87==24 | IT_OCC87==25 | IT_OCC87==42 | IT_OCC87==46) & (SELFEMP==2 | SELFEMP==.)
replace IT87_class8=6 if IT_OCC87==26 & (SELFEMP==2 | SELFEMP==.)
replace IT87_class8=7 if (IT_OCC87==13 | IT_OCC87==22 | IT_OCC87==23) & (SELFEMP==2 | SELFEMP==.)
replace IT87_class8=8 if (IT_OCC87==33 | IT_OCC87==41 | IT_OCC87==45) & (SELFEMP==2 | SELFEMP==.)
replace IT87_class8=. if IT_OCC87==32


*************************************************
* Create Oesch 5-Class schema for respondent
* Create IT87_class5
* Using IT_OCC87 and SELFEMP
*************************************************
gen IT87_class5=.

replace IT87_class5=1 if (IT_OCC87==11 | IT_OCC87==12 | IT_OCC87==14) & SELFEMP==1
*NB1: no accurate distiction is possible between big business holder (IT87_class5=1) and small business holder (IT87_class5=3): all "Entrepreneurs, manufacturers" have been assigned to IT87_class5==1.

replace IT87_class5=1 if (IT_OCC87==21 | IT_OCC87==22 | IT_OCC87==23) & (SELFEMP==2 | SELFEMP==.)

replace IT87_class5=2 if (IT_OCC87==13 | IT_OCC87==24 |IT_OCC87==25| IT_OCC87==26 | IT_OCC87==42 | IT_OCC87==46) & (SELFEMP==2 | SELFEMP==.)
*NB2: No tecnical experts (IT87_class5=1) or tecnicians (IT87_class5=2) can be identified accordig to the disposable categories in IT_OCC87

replace IT87_class5=3 if (IT_OCC87==43 | IT_OCC87==44 |IT_OCC87==46) & (SELFEMP==1)

replace IT87_class5=4 if (IT_OCC87==41) & (SELFEMP==2 | SELFEMP==.)
replace IT87_class5=5 if (IT_OCC87==31 | IT_OCC87==33| IT_OCC87==34 | IT_OCC87==45) & (SELFEMP==2 | SELFEMP==.)
*NB: no accurate distiction between skilled workers (IT87_class5=4) and unskilled  (IT87_class5=5) workers is possible: all "Workers, operatives or similar" has been assigned to IT87_class5=5.


*************************************************
* Create Oesch 8-Class schema for partner
* Create IT87_pclass8
* Using IT_SOC87 and SPSELFEM
*************************************************

gen IT87_pclass8=.

replace IT87_pclass8=1 if (IT_SOC87==11 | IT_SOC87==12 | IT_SOC87==14) & SPSELFEM==1
replace IT87_pclass8=2 if (IT_SOC87==44 | IT_SOC87==43 | IT_OCC87==46) & SELFEMP==1
*NB1: no accurate distiction is possible between big business holder (IT87_pclass8=1) and small business holder (IT87_pclass8=2)
*NB2: No tecnical experts or tecnicians (IT87_pclass8=3) can be identified 

replace IT87_pclass8=4 if (IT_SOC87==31 | IT_SOC87==34 | IT_SOC87==43) & (SELFEMP==2 | SELFEMP==.)
replace IT87_pclass8=5 if (IT_SOC87==21 | IT_SOC87==24 | IT_SOC87==25 | IT_SOC87==42 | IT_SOC87==46) & (SELFEMP==2 | SELFEMP==.)
replace IT87_pclass8=6 if IT_SOC87==26 & (SELFEMP==2 | SELFEMP==.)
replace IT87_pclass8=7 if (IT_SOC87==13 | IT_SOC87==22 | IT_SOC87==23) & (SELFEMP==2 | SELFEMP==.)
replace IT87_pclass8=8 if (IT_SOC87==33 | IT_SOC87==41 | IT_SOC87==45) & (SELFEMP==2 | SELFEMP==.)

replace IT87_pclass8=. if IT_SOC87==32


*************************************************
* Create Oesch 5-Class schema for partner
* Create IT87_pclass5
* Using IT_SOC87 and SPSELFEM
*************************************************
gen IT87_pclass5=. 

replace IT87_pclass5=1 if (IT_SOC87==11 | IT_SOC87==12 | IT_SOC87==14) & SPSELFEM==1
*NB1: no accurate distiction is possible between big business holder (IT87_pclass5=1) and small business holder (IT87_pclass5=3): all "Entrepreneurs, manufacturers" have been assigned to IT87_pclass5==1.

replace IT87_pclass5=1 if (IT_SOC87==21 | IT_SOC87==22 | IT_SOC87==23) & (SPSELFEM==2 | SPSELFEM==.)

replace IT87_pclass5=2 if (IT_SOC87==13 | IT_SOC87==24 |IT_SOC87==25| IT_SOC87==26 | IT_SOC87==42 | IT_SOC87==46) & (SPSELFEM==2 | SPSELFEM==.)
*NB2: No tecnical experts (IT87_class5=1) or tecnicians (IT87_class5=2) can be identified accordig to the disposable categories in IT_OCC87

replace IT87_pclass5=3 if (IT_SOC87==43 | IT_SOC87==44 |IT_SOC87==46) & (SPSELFEM==1)

replace IT87_pclass5=4 if (IT_SOC87==41) & (SPSELFEM==2 | SPSELFEM==.)
replace IT87_pclass5=5 if (IT_SOC87==31 | IT_SOC87==33| IT_SOC87==34 | IT_SOC87==45) & (SPSELFEM==2 | SPSELFEM==.)
*NB: no accurate distiction between skilled workers (IT87_pclass5=4) and unskilled  (IT87_pclass5=5) workers is possible: all "Workers, operatives or similar" has been assigned to IT87_pclass5=5.


*************************************************
*recode class8 and class5 for Italy 1987
*using IT87_class8, IT87_class5, IT87_pclass8 and IT87_pclass5
*************************************************
replace class8_r=IT87_class8 if COUNTRY==380 & YEAR==1987
replace class8_p=IT87_pclass8 if COUNTRY==380 & YEAR==1987

replace class8=IT87_class8 if COUNTRY==380 & YEAR==1987
replace class8=IT87_pclass8 if IT87_class8==. & COUNTRY==380 & YEAR==1987

replace class5_r=IT87_class5 if COUNTRY==380 & YEAR==1987
replace class5_p=IT87_pclass5 if COUNTRY==380 & YEAR==1987

replace class5=IT87_class5 if COUNTRY==380 & YEAR==1987
replace class5=IT87_pclass5 if IT87_class5==. & COUNTRY==380 & YEAR==1987



*******************************************************************************
* SPECIFIC Oesch’s class schema for ITALY 1992
* NB: Due to the lack of information, only 8-Class schema and 5-Class schema can be created
*******************************************************************************

*************************************************
* Create Oesch 8-Class schema for respondent
* Create IT92_class8
* Using IT_OCC92 and SELFEMP
*************************************************

gen IT92_class8=.

replace IT92_class8=1 if (IT_OCC92==1 | IT_OCC92==2 | IT_OCC92==4) & SELFEMP==1
replace IT92_class8=2 if (IT_OCC92==19 | IT_OCC92==18 | IT_OCC92==21) & SELFEMP==1
*NB1: no accurate distiction is possible between big business holder (IT92_class8=1) and small business holder (IT92_class8=2): all "Entrepreneurs, manufacturers" have been assigned to IT92_class8==1.
*NB2: No tecnical experts or tecnicians (IT92_class8=3) can be identified 

replace IT92_class8=4 if (IT_OCC92==12 | IT_OCC92==15 | IT_OCC92==18) & (SELFEMP==2 | SELFEMP==.)
replace IT92_class8=5 if (IT_OCC92==16 | IT_OCC92==8 | IT_OCC92==9 | IT_OCC92==17 | IT_OCC92==21) & (SELFEMP==2 | SELFEMP==.)
replace IT92_class8=6 if IT_OCC92==10 & (SELFEMP==2 | SELFEMP==.)
replace IT92_class8=7 if (IT_OCC92==3 | IT_OCC92==6 | IT_OCC92==7) & (SELFEMP==2 | SELFEMP==.)
replace IT92_class8=8 if (IT_OCC92==14 | IT_OCC92==16 | IT_OCC92==20 | IT_OCC92==22) & (SELFEMP==2 | SELFEMP==.)
replace IT92_class8=. if IT_OCC92==32


*************************************************
* Create Oesch 5-Class schema for respondent
* Create IT92_class5
* Using IT_OCC92 and SELFEMP
*************************************************
gen IT92_class5=.

replace IT92_class5=1 if (IT_OCC92==1 | IT_OCC92==2 | IT_OCC92==4) & SELFEMP==1
*NB1: no accurate distiction is possible between big business holder (IT92_class5=1) and small business holder (IT92_class5=3): all "Entrepreneurs, manufacturers" have been assigned to IT92_class5==1.

replace IT92_class5=1 if (IT_OCC92==5 | IT_OCC92==6 | IT_OCC92==7) & (SELFEMP==2 | SELFEMP==.)

replace IT92_class5=2 if (IT_OCC92==3 | IT_OCC92==8 |IT_OCC92==9| IT_OCC92==10 | IT_OCC92==17 | IT_OCC92==21) & (SELFEMP==2 | SELFEMP==.)
*NB2: No tecnical experts (IT92_class5=1) or tecnicians (IT92_class5=2) can be identified accordig to the disposable categories in IT_OCC92

replace IT92_class5=3 if (IT_OCC92==18 | IT_OCC92==19 |IT_OCC92==21) & (SELFEMP==1)

replace IT92_class5=4 if (IT_OCC92==16) & (SELFEMP==2 | SELFEMP==.)
replace IT92_class5=5 if (IT_OCC92==12 | IT_OCC92==13| IT_OCC92==15 | IT_OCC92==20) & (SELFEMP==2 | SELFEMP==.)
*NB: no accurate distiction between skilled workers (IT92_class5=4) and unskilled  (IT92_class5=5) workers is possible: all "Workers, operatives or similar" has been assigned to IT92_class5=5.


*************************************************
* Create Oesch 8-Class schema for partner
* Create IT92_pclass8
* Using IT_SOC92 and SPSELFEM
*************************************************

gen IT92_pclass8=.

replace IT92_pclass8=1 if (IT_SOC92==1 | IT_SOC92==2 | IT_SOC92==4) & SPSELFEM==1
replace IT92_pclass8=2 if (IT_SOC92==19 | IT_SOC92==18 | IT_SOC92==21) & SPSELFEM==1
*NB1: no accurate distiction is possible between big business holder (IT92_class8=1) and small business holder (IT92_class8=2): all "Entrepreneurs, manufacturers" have been assigned to IT92_class8==1.
*NB2: No tecnical experts or tecnicians (IT92_class8=3) can be identified 

replace IT92_pclass8=4 if (IT_SOC92==12 | IT_SOC92==15 | IT_SOC92==18) & (SPSELFEM==2 | SELFEMP==.)
replace IT92_pclass8=5 if (IT_SOC92==16 | IT_SOC92==8 | IT_SOC92==9 | IT_SOC92==17 | IT_SOC92==21) & (SPSELFEM==2 | SPSELFEM==.)
replace IT92_pclass8=6 if IT_SOC92==10 & (SPSELFEM==2 | SPSELFEM==.)
replace IT92_pclass8=7 if (IT_SOC92==3 | IT_SOC92==6 | IT_SOC92==7) & (SPSELFEM==2 | SPSELFEM==.)
replace IT92_pclass8=8 if (IT_OCC92==14 | IT_OCC92==16 | IT_OCC92==20 | IT_OCC92==22) & (SPSELFEM==2 | SPSELFEM==.)
replace IT92_pclass8=. if IT_OCC92==32


*************************************************
* Create Oesch 5-Class schema for partner
* Create IT92_pclass5
* Using IT_OCC92 and SPSELFEM
*************************************************
gen IT92_pclass5=.

replace IT92_pclass5=1 if (IT_SOC92==1 | IT_SOC92==2 | IT_SOC92==4) & SPSELFEM==1
*NB1: no accurate distiction is possible between big business holder (IT92_class5=1) and small business holder (IT92_class5=3): all "Entrepreneurs, manufacturers" have been assigned to IT92_class5==1.

replace IT92_pclass5=1 if (IT_SOC92==5 | IT_SOC92==6 | IT_SOC92==7) & (SPSELFEM==2 | SPSELFEM==.)

replace IT92_pclass5=2 if (IT_SOC92==3 | IT_SOC92==8 |IT_SOC92==9| IT_SOC92==10 | IT_SOC92==17 | IT_SOC92==21) & (SPSELFEM==2 | SPSELFEM==.)
*NB2: No tecnical experts (IT92_class5=1) or tecnicians (IT92_class5=2) can be identified accordig to the disposable categories in IT_OCC92

replace IT92_pclass5=3 if (IT_SOC92==18 | IT_SOC92==19 |IT_SOC92==21) & (SPSELFEM==1)

replace IT92_pclass5=4 if (IT_SOC92==16) & (SPSELFEM==2 | SPSELFEM==.)
replace IT92_pclass5=5 if (IT_SOC92==12 | IT_SOC92==13| IT_SOC92==15 | IT_SOC92==20) & (SPSELFEM==2 | SPSELFEM==.)
*NB: no accurate distiction between skilled workers (IT92_class5=4) and unskilled  (IT92_class5=5) workers is possible: all "Workers, operatives or similar" has been assigned to IT92_class5=5.


*************************************************
*recode class8 and class5 for Italy 1992
*using IT92_class8, IT92_class5, IT92_pclass8 and IT92_pclass5
*************************************************
replace class8_r=IT92_class8 if COUNTRY==380 & YEAR==1992
replace class8_p=IT92_pclass8 if COUNTRY==380 & YEAR==1992

replace class8=IT92_class8 if COUNTRY==380 & YEAR==1992
replace class8=IT92_pclass8 if IT92_class8==. & COUNTRY==380 & YEAR==1992

replace class5_r=IT92_class5 if COUNTRY==380 & YEAR==1992
replace class5_p=IT92_pclass5 if COUNTRY==380 & YEAR==1992

replace class5=IT92_class5 if COUNTRY==380 & YEAR==1992
replace class5=IT92_pclass5 if IT92_class5==. & COUNTRY==360 & YEAR==1992


save, replace



*******************************************************************************
*******************************************************************************
*******************************************************************************
* Create 16-Class schema, 8-Class schema and 5-Class schema
* Data: ISSP 2014-2017 (containing ISCO08 codes)
* June 2020
* Nathalie Vigna, University of Lausanne
*******************************************************************************
use "$path\DATASET_1987-2018.dta", clear
keep if YEAR>2013

save "$path\DATASET_2014-18_class.dta", replace
use "$path\DATASET_2014-18_class.dta", clear

*******************************************************************************
*CLASS SCHEMA
*NB: The variable names are not always identical among the year datasets: it is necessary to check for each variable and to rename it. 
*******************************************************************************

*******************************************************************************
* Respondent's Oesch class position
* Recode and create variables used to construct class variable for respondents
* Variables used to construct class variable for respondents: ISCO08, EMPREL, NEMPLOY 
*******************************************************************************
 
**** Recode occupation variable (isco08 com-4-digit) for respondents

tab ISCO08, m
 
recode ISCO08 (missing=-9), copyrest gen(isco08_mainjob)
recode isco08_mainjob (0=-9)
label variable isco08_mainjob "Current occupation of respondent - isco08 4-digit"
tab isco08_mainjob


**** Recode employment status for respondents
 
recode NEMPLOY (1/9=1)(10/9990=2)(.=.) (.a=.) (.n=.) (9997=.) (9998=.) (9999=.), gen(emplno_r)
label define emplno_r ///
0 "0 employees" ///
1 "1-9 employees" ///
2 "10+ employees"
label value emplno_r emplno_r
tab emplno_r
									
gen selfemp_r=9
replace selfemp_r=1 if emplno_r==1 | emplno_r==2 | EMPREL==2 | EMPREL==3 | EMPREL==4
replace selfemp_r=2 if EMPREL==1
label define selfemp_r 1"Self-employed" 2 "Employee" 9 "Missing"
label value selfemp_r selfemp_r			
tab selfemp_r

gen selfem_mainjob=.
replace selfem_mainjob=1 if selfemp_r==2 | selfemp_r==9
replace selfem_mainjob=2 if (selfemp_r==1 & (emplno_r==0 | emplno_r==.)) | EMPREL==2 | EMPREL==4
replace selfem_mainjob=3 if (selfemp_r==1 | selfemp_r==9) & emplno_r==1 
replace selfem_mainjob=4 if (selfemp_r==1 | selfemp_r==9) & emplno_r==2
label variable selfem_mainjob "Employment status for respondants"
label define selfem_mainjob 1 "Not self-employed" 2 "Self-empl without employees" 3 "Self-empl with 1-9 employees" 4 "Self-empl with 10 or more" 
label value selfem_mainjob selfem_mainjob
tab selfem_mainjob, m
                                 
***NB1: selfem_mainjob=1 if selfemp_r==9 -> people we don't know if they are self-employed or not are considered to be employees
***NB2: selfem_mainjob=2 selfemp_r==1 & emplno_r==. -> self-employed people we don't know how many employees they have are considered to be self-employed without employees

*************************************************
* Create Oesch class schema for respondents
* Create class16_r class8_r class5_r
* Using isco08_mainjob and selfem_mainjob
*************************************************

gen class16_r = -9

* Large employers (1)

replace class16_r=1 if selfem_mainjob==4

* Self-employed professionals (2)

replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob >= 2000 & isco08_mainjob <= 2162) 
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob >= 2164 & isco08_mainjob <= 2165) 
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob >= 2200 & isco08_mainjob <= 2212) 
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob == 2250)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob >= 2261 & isco08_mainjob <= 2262)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob >= 2300 & isco08_mainjob <= 2330)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob >= 2350 & isco08_mainjob <= 2352)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob >= 2359 & isco08_mainjob <= 2432)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob >= 2500 & isco08_mainjob <= 2619)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob == 2621)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob >= 2630 & isco08_mainjob <= 2634)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob >= 2636 & isco08_mainjob <= 2640)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob >= 2642 & isco08_mainjob <= 2643)

* Small business owners with employees (3)

replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob >= 1000 & isco08_mainjob <= 1439)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob == 2163)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob == 2166)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob >= 2220 & isco08_mainjob <= 2240)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob == 2260)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob >= 2263 & isco08_mainjob <= 2269)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob >= 2340 & isco08_mainjob <= 2342)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob >= 2353 & isco08_mainjob <= 2356)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob >= 2433 & isco08_mainjob <= 2434)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob == 2620)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob == 2622)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob == 2635)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob == 2641)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob >= 2650 & isco08_mainjob <= 2659)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob >= 3000 & isco08_mainjob <= 9629)

* Small business owners without employees (4)

replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob >= 1000 & isco08_mainjob <= 1439)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob == 2163)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob == 2166)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob >= 2220 & isco08_mainjob <= 2240)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob == 2260)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob >= 2263 & isco08_mainjob <= 2269)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob >= 2340 & isco08_mainjob <= 2342)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob >= 2353 & isco08_mainjob <= 2356)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob >= 2433 & isco08_mainjob <= 2434)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob == 2620)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob == 2622)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob == 2635)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob == 2641)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob >= 2650 & isco08_mainjob <= 2659)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob >= 3000 & isco08_mainjob <= 9629)

* Technical experts (5)

replace class16_r=5 if (selfem_mainjob==1) & (isco08_mainjob >= 2100 & isco08_mainjob <= 2162)
replace class16_r=5 if (selfem_mainjob==1) & (isco08_mainjob >= 2164 & isco08_mainjob <= 2165)
replace class16_r=5 if (selfem_mainjob==1) & (isco08_mainjob >= 2500 & isco08_mainjob <= 2529)

* Technicians (6)

replace class16_r=6 if (selfem_mainjob==1) & (isco08_mainjob >= 3100 & isco08_mainjob <= 3155)
replace class16_r=6 if (selfem_mainjob==1) & (isco08_mainjob >= 3210 & isco08_mainjob <= 3214)
replace class16_r=6 if (selfem_mainjob==1) & (isco08_mainjob == 3252)
replace class16_r=6 if (selfem_mainjob==1) & (isco08_mainjob >= 3500 & isco08_mainjob <= 3522)

* Skilled manual (7)

replace class16_r=7 if (selfem_mainjob==1) & (isco08_mainjob >= 6000 & isco08_mainjob <= 7549)
replace class16_r=7 if (selfem_mainjob==1) & (isco08_mainjob >= 8310 & isco08_mainjob <= 8312)
replace class16_r=7 if (selfem_mainjob==1) & (isco08_mainjob == 8330)
replace class16_r=7 if (selfem_mainjob==1) & (isco08_mainjob >= 8332 & isco08_mainjob <= 8340)
replace class16_r=7 if (selfem_mainjob==1) & (isco08_mainjob >= 8342 & isco08_mainjob <= 8344)

* Low-skilled manual (8)

replace class16_r=8 if (selfem_mainjob==1) & (isco08_mainjob >= 8000 & isco08_mainjob <= 8300)
replace class16_r=8 if (selfem_mainjob==1) & (isco08_mainjob >= 8320 & isco08_mainjob <= 8321)
replace class16_r=8 if (selfem_mainjob==1) & (isco08_mainjob == 8341)
replace class16_r=8 if (selfem_mainjob==1) & (isco08_mainjob == 8350)
replace class16_r=8 if (selfem_mainjob==1) & (isco08_mainjob >= 9200 & isco08_mainjob <= 9334)
replace class16_r=8 if (selfem_mainjob==1) & (isco08_mainjob >= 9600 & isco08_mainjob <= 9620)
replace class16_r=8 if (selfem_mainjob==1) & (isco08_mainjob >= 9622 & isco08_mainjob <= 9629)

* Higher-grade managers and administrators (9)

replace class16_r=9 if (selfem_mainjob==1) & (isco08_mainjob >= 1000 & isco08_mainjob <= 1300)
replace class16_r=9 if (selfem_mainjob==1) & (isco08_mainjob >= 1320 & isco08_mainjob <= 1349)
replace class16_r=9 if (selfem_mainjob==1) & (isco08_mainjob >= 2400 & isco08_mainjob <= 2432)
replace class16_r=9 if (selfem_mainjob==1) & (isco08_mainjob >= 2610 & isco08_mainjob <= 2619)
replace class16_r=9 if (selfem_mainjob==1) & (isco08_mainjob == 2631)
replace class16_r=9 if (selfem_mainjob==1) & (isco08_mainjob >= 100 & isco08_mainjob <= 110)

* Lower-grade managers and administrators (10)

replace class16_r=10 if (selfem_mainjob==1) & (isco08_mainjob >= 1310 & isco08_mainjob <= 1312)
replace class16_r=10 if (selfem_mainjob==1) & (isco08_mainjob >= 1400 & isco08_mainjob <= 1439)
replace class16_r=10 if (selfem_mainjob==1) & (isco08_mainjob >= 2433 & isco08_mainjob <= 2434)
replace class16_r=10 if (selfem_mainjob==1) & (isco08_mainjob >= 3300 & isco08_mainjob <= 3339)
replace class16_r=10 if (selfem_mainjob==1) & (isco08_mainjob == 3343)
replace class16_r=10 if (selfem_mainjob==1) & (isco08_mainjob >= 3350 & isco08_mainjob <= 3359)
replace class16_r=10 if (selfem_mainjob==1) & (isco08_mainjob == 3411)
replace class16_r=10 if (selfem_mainjob==1) & (isco08_mainjob == 5221)
replace class16_r=10 if (selfem_mainjob==1) & (isco08_mainjob >= 200 & isco08_mainjob <= 210)

* Skilled clerks (11)

replace class16_r=11 if (selfem_mainjob==1) & (isco08_mainjob >= 3340 & isco08_mainjob <= 3342)
replace class16_r=11 if (selfem_mainjob==1) & (isco08_mainjob == 3344)
replace class16_r=11 if (selfem_mainjob==1) & (isco08_mainjob >= 4000 & isco08_mainjob <= 4131)
replace class16_r=11 if (selfem_mainjob==1) & (isco08_mainjob >= 4200 & isco08_mainjob <= 4221)
replace class16_r=11 if (selfem_mainjob==1) & (isco08_mainjob >= 4224 & isco08_mainjob <= 4413)
replace class16_r=11 if (selfem_mainjob==1) & (isco08_mainjob >= 4415 & isco08_mainjob <= 4419)

* Unskilled clerks (12)

replace class16_r=12 if (selfem_mainjob==1) & (isco08_mainjob == 4132)
replace class16_r=12 if (selfem_mainjob==1) & (isco08_mainjob == 4222)
replace class16_r=12 if (selfem_mainjob==1) & (isco08_mainjob == 4223)
replace class16_r=12 if (selfem_mainjob==1) & (isco08_mainjob == 5230)
replace class16_r=12 if (selfem_mainjob==1) & (isco08_mainjob == 9621)

* Socio-cultural professionals (13)

replace class16_r=13 if (selfem_mainjob==1) & (isco08_mainjob >= 2200 &  isco08_mainjob <= 2212)
replace class16_r=13 if (selfem_mainjob==1) & (isco08_mainjob == 2250)
replace class16_r=13 if (selfem_mainjob==1) & (isco08_mainjob >= 2261 &  isco08_mainjob <= 2262)
replace class16_r=13 if (selfem_mainjob==1) & (isco08_mainjob >= 2300 &  isco08_mainjob <= 2330)
replace class16_r=13 if (selfem_mainjob==1) & (isco08_mainjob >= 2350 &  isco08_mainjob <= 2352)
replace class16_r=13 if (selfem_mainjob==1) & (isco08_mainjob == 2359)
replace class16_r=13 if (selfem_mainjob==1) & (isco08_mainjob == 2600)
replace class16_r=13 if (selfem_mainjob==1) & (isco08_mainjob == 2621)
replace class16_r=13 if (selfem_mainjob==1) & (isco08_mainjob == 2630)
replace class16_r=13 if (selfem_mainjob==1) & (isco08_mainjob >= 2632 &  isco08_mainjob <= 2634)
replace class16_r=13 if (selfem_mainjob==1) & (isco08_mainjob >= 2636 &  isco08_mainjob <= 2640)
replace class16_r=13 if (selfem_mainjob==1) & (isco08_mainjob >= 2642 &  isco08_mainjob <= 2643)

* Socio-cultural semi-professionals (14)

replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob == 2163)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob == 2166)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob >= 2220 & isco08_mainjob <= 2240)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob == 2260)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob >= 2263 & isco08_mainjob <= 2269)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob >= 2340 & isco08_mainjob <= 2342)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob >= 2353 & isco08_mainjob <= 2356)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob == 2620)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob == 2622)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob == 2635)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob == 2641)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob >= 2650 & isco08_mainjob <= 2659)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob == 3200)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob >= 3220 & isco08_mainjob <= 3230)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob == 3250)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob >= 3253 & isco08_mainjob <= 3257)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob == 3259)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob >= 3400 & isco08_mainjob <= 3410)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob >= 3412 & isco08_mainjob <= 3413)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob >= 3430 & isco08_mainjob <= 3433)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob == 3435)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob == 4414)

* Skilled service (15)

replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob == 3240)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob == 3251)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob == 3258)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob >= 3420 & isco08_mainjob <= 3423)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob == 3434)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob >= 5000 & isco08_mainjob <= 5120)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob >= 5140 & isco08_mainjob <= 5142)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob == 5163)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob == 5165)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob == 5200)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob == 5220)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob >= 5222 & isco08_mainjob <= 5223)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob >= 5241 & isco08_mainjob <= 5242)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob >= 5300 & isco08_mainjob <= 5321)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob >= 5400 & isco08_mainjob <= 5413)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob == 5419)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob == 8331)

* Low-skilled service (16)

replace class16_r=16 if (selfem_mainjob==1) & (isco08_mainjob >= 5130 & isco08_mainjob <= 5132)
replace class16_r=16 if (selfem_mainjob==1) & (isco08_mainjob >= 5150 & isco08_mainjob <= 5162)
replace class16_r=16 if (selfem_mainjob==1) & (isco08_mainjob == 5164)
replace class16_r=16 if (selfem_mainjob==1) & (isco08_mainjob == 5169)
replace class16_r=16 if (selfem_mainjob==1) & (isco08_mainjob >= 5210 & isco08_mainjob <= 5212)
replace class16_r=16 if (selfem_mainjob==1) & (isco08_mainjob == 5240)
replace class16_r=16 if (selfem_mainjob==1) & (isco08_mainjob >= 5243 & isco08_mainjob <= 5249)
replace class16_r=16 if (selfem_mainjob==1) & (isco08_mainjob >= 5322 & isco08_mainjob <= 5329)
replace class16_r=16 if (selfem_mainjob==1) & (isco08_mainjob == 5414)
replace class16_r=16 if (selfem_mainjob==1) & (isco08_mainjob == 8322)
replace class16_r=16 if (selfem_mainjob==1) & (isco08_mainjob >= 9100 & isco08_mainjob <= 9129)
replace class16_r=16 if (selfem_mainjob==1) & (isco08_mainjob >= 9400 & isco08_mainjob <= 9520)


***NB: a missing value in class16_r when isco08_mainjob!=. means that the value of selfem_mainjob was not coherent with the job type


mvdecode class16_r, mv(-9)
label variable class16_r "Respondent's Oesch class position - 16 classes"
label define class16_r ///
1 "Large employers" ///
2 "Self-employed professionals" ///
3 "Small business owners with employees" ///
4 "Small business owners without employees" ///
5 "Technical experts" ///
6 "Technicians" ///
7 "Skilled manual" ///
8 "Low-skilled manual" ///
9 "Higher-grade managers and administrators" ///
10 "Lower-grade managers and administrators" ///
11 "Skilled clerks" ///
12 "Unskilled clerks" ///
13 "Socio-cultural professionals" ///
14 "Socio-cultural semi-professionals" ///
15 "Skilled service" ///
16 "Low-skilled service"
label value class16_r class16_r
tab class16_r
 
recode class16_r (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8), gen(class8_r)
label variable class8_r "Respondent's Oesch class position - 8 classes"
label define class8_r ///
1 "Self-employed professionals and large employers" ///
2 "Small business owners" ///
3 "Technical (semi-)professionals" ///
4 "Production workers" ///
5 "(Associate) managers" ///
6 "Clerks" ///
7 "Socio-cultural (semi-)professionals" ///
8 "Service workers"
label value class8_r class8_r
tab class8_r

recode class16_r (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5), gen(class5_r)
label variable class5_r "Respondent's Oesch class position - 5 classes"
label define  class5_r ///
1 "Higher-grade service class" ///
2 "Lower-grade service class" ///
3 "Small business owners" ///
4 "Skilled workers" ///
5 "Unskilled workers"
label value class5_r class5_r
tab class5_r



*******************************************************************************
* Partner's Oesch class position
* Recode and create variables used to construct class variable for partners
* Variables used to construct class variable for partners: SPISCO08, SPEMPREL
* NB: Partners we don't know if they are self-employed or not are considered to be employees
*******************************************************************************

recode SPISCO08 (missing=-9), copyrest gen(isco08_partner)
recode isco08_partner (0=-9)
label variable isco08_partner "Current occupation of partner - isco08 4-digit"

gen selfem_partner=9
label define selfem_partner 1"Self-employed" 2 "Employee" 9 "Missing"
label value selfem_partner selfem_partner			

replace selfem_partner=1 if SPEMPREL==2 | SPEMPREL==3 | SPEMPREL==4 | SPEMPREL==5
replace selfem_partner=2 if SPEMPREL==1

 
*************************************************
* Create Oesch class schema for partners
* Create class16_p class8_p class5_p
* Using isco08_partner and selfem_partner
*************************************************

gen class16_p = -9

* Large employers (1)



* Self-employed professionals (2)

replace class16_p=2 if (selfem_partner==1) & (isco08_partner >= 2000 & isco08_partner <= 2162)
replace class16_p=2 if (selfem_partner==1) & (isco08_partner >= 2164 & isco08_partner <= 2165)
replace class16_p=2 if (selfem_partner==1) & (isco08_partner >= 2200 & isco08_partner <= 2212)
replace class16_p=2 if (selfem_partner==1) & (isco08_partner == 2250)
replace class16_p=2 if (selfem_partner==1) & (isco08_partner >= 2261 & isco08_partner <= 2262)
replace class16_p=2 if (selfem_partner==1) & (isco08_partner >= 2300 & isco08_partner <= 2330)
replace class16_p=2 if (selfem_partner==1) & (isco08_partner >= 2350 & isco08_partner <= 2352)
replace class16_p=2 if (selfem_partner==1) & (isco08_partner >= 2359 & isco08_partner <= 2432)
replace class16_p=2 if (selfem_partner==1) & (isco08_partner >= 2500 & isco08_partner <= 2619)
replace class16_p=2 if (selfem_partner==1) & (isco08_partner == 2621)
replace class16_p=2 if (selfem_partner==1) & (isco08_partner >= 2630 & isco08_partner <= 2634)
replace class16_p=2 if (selfem_partner==1) & (isco08_partner >= 2636 & isco08_partner <= 2640)
replace class16_p=2 if (selfem_partner==1) & (isco08_partner >= 2642 & isco08_partner <= 2643)

* Small business owners with employees (3)
 


* Small business owners without employees (4)

replace class16_p=4 if (selfem_partner==1) & (isco08_partner >= 1000 & isco08_partner <= 1439)
replace class16_p=4 if (selfem_partner==1) & (isco08_partner == 2163)
replace class16_p=4 if (selfem_partner==1) & (isco08_partner == 2166)
replace class16_p=4 if (selfem_partner==1) & (isco08_partner >= 2220 & isco08_partner <= 2240)
replace class16_p=4 if (selfem_partner==1) & (isco08_partner == 2260)
replace class16_p=4 if (selfem_partner==1) & (isco08_partner >= 2263 & isco08_partner <= 2269)
replace class16_p=4 if (selfem_partner==1) & (isco08_partner >= 2340 & isco08_partner <= 2342)
replace class16_p=4 if (selfem_partner==1) & (isco08_partner >= 2353 & isco08_partner <= 2356)
replace class16_p=4 if (selfem_partner==1) & (isco08_partner >= 2433 & isco08_partner <= 2434)
replace class16_p=4 if (selfem_partner==1) & (isco08_partner == 2620)
replace class16_p=4 if (selfem_partner==1) & (isco08_partner == 2622)
replace class16_p=4 if (selfem_partner==1) & (isco08_partner == 2635)
replace class16_p=4 if (selfem_partner==1) & (isco08_partner == 2641)
replace class16_p=4 if (selfem_partner==1) & (isco08_partner >= 2650 & isco08_partner <= 2659)
replace class16_p=4 if (selfem_partner==1) & (isco08_partner >= 3000 & isco08_partner <= 9629)

* Technical experts (5)

replace class16_p=5 if (selfem_partner==2) & (isco08_partner >= 2100 & isco08_partner <= 2162)
replace class16_p=5 if (selfem_partner==2) & (isco08_partner >= 2164 & isco08_partner <= 2165)
replace class16_p=5 if (selfem_partner==2) & (isco08_partner >= 2500 & isco08_partner <= 2529)

* Technicians (6)

replace class16_p=6 if (selfem_partner==2) & (isco08_partner >= 3100 & isco08_partner <= 3155)
replace class16_p=6 if (selfem_partner==2) & (isco08_partner >= 3210 & isco08_partner <= 3214)
replace class16_p=6 if (selfem_partner==2) & (isco08_partner == 3252)
replace class16_p=6 if (selfem_partner==2) & (isco08_partner >= 3500 & isco08_partner <= 3522)

* Skilled manual (7)

replace class16_p=7 if (selfem_partner==2) & (isco08_partner >= 6000 & isco08_partner <= 7549)
replace class16_p=7 if (selfem_partner==2) & (isco08_partner >= 8310 & isco08_partner <= 8312)
replace class16_p=7 if (selfem_partner==2) & (isco08_partner == 8330)
replace class16_p=7 if (selfem_partner==2) & (isco08_partner >= 8332 & isco08_partner <= 8340)
replace class16_p=7 if (selfem_partner==2) & (isco08_partner >= 8342 & isco08_partner <= 8344)

* Low-skilled manual (8)

replace class16_p=8 if (selfem_partner==2) & (isco08_partner >= 8000 & isco08_partner <= 8300)
replace class16_p=8 if (selfem_partner==2) & (isco08_partner >= 8320 & isco08_partner <= 8321)
replace class16_p=8 if (selfem_partner==2) & (isco08_partner == 8341)
replace class16_p=8 if (selfem_partner==2) & (isco08_partner == 8350)
replace class16_p=8 if (selfem_partner==2) & (isco08_partner >= 9200 & isco08_partner <= 9334)
replace class16_p=8 if (selfem_partner==2) & (isco08_partner >= 9600 & isco08_partner <= 9620)
replace class16_p=8 if (selfem_partner==2) & (isco08_partner >= 9622 & isco08_partner <= 9629)

* Higher-grade managers and administrators (9)

replace class16_p=9 if (selfem_partner==2) & (isco08_partner >= 1000 & isco08_partner <= 1300)
replace class16_p=9 if (selfem_partner==2) & (isco08_partner >= 1320 & isco08_partner <= 1349)
replace class16_p=9 if (selfem_partner==2) & (isco08_partner >= 2400 & isco08_partner <= 2432)
replace class16_p=9 if (selfem_partner==2) & (isco08_partner >= 2610 & isco08_partner <= 2619)
replace class16_p=9 if (selfem_partner==2) & (isco08_partner == 2631)
replace class16_p=9 if (selfem_partner==2) & (isco08_partner >= 100 & isco08_partner <= 110)

* Lower-grade managers and administrators (10)


replace class16_p=10 if (selfem_partner==2) & (isco08_partner >= 1310 & isco08_partner <= 1312)
replace class16_p=10 if (selfem_partner==2) & (isco08_partner >= 1400 & isco08_partner <= 1439)
replace class16_p=10 if (selfem_partner==2) & (isco08_partner >= 2433 & isco08_partner <= 2434)
replace class16_p=10 if (selfem_partner==2) & (isco08_partner >= 3300 & isco08_partner <= 3339)
replace class16_p=10 if (selfem_partner==2) & (isco08_partner == 3343)
replace class16_p=10 if (selfem_partner==2) & (isco08_partner >= 3350 & isco08_partner <= 3359)
replace class16_p=10 if (selfem_partner==2) & (isco08_partner == 3411)
replace class16_p=10 if (selfem_partner==2) & (isco08_partner == 5221)
replace class16_p=10 if (selfem_partner==2) & (isco08_partner >= 200 & isco08_partner <= 210)

* Skilled clerks (11)

replace class16_p=11 if (selfem_partner==2) & (isco08_partner >= 3340 & isco08_partner <= 3342)
replace class16_p=11 if (selfem_partner==2) & (isco08_partner == 3344)
replace class16_p=11 if (selfem_partner==2) & (isco08_partner >= 4000 & isco08_partner <= 4131)
replace class16_p=11 if (selfem_partner==2) & (isco08_partner >= 4200 & isco08_partner <= 4221)
replace class16_p=11 if (selfem_partner==2) & (isco08_partner >= 4224 & isco08_partner <= 4413)
replace class16_p=11 if (selfem_partner==2) & (isco08_partner >= 4415 & isco08_partner <= 4419)

* Unskilled clerks (12)

replace class16_p=12 if (selfem_partner==2) & (isco08_partner == 4132)
replace class16_p=12 if (selfem_partner==2) & (isco08_partner == 4222)
replace class16_p=12 if (selfem_partner==2) & (isco08_partner == 4223)
replace class16_p=12 if (selfem_partner==2) & (isco08_partner == 5230)
replace class16_p=12 if (selfem_partner==2) & (isco08_partner == 9621)

* Socio-cultural professionals (13)

replace class16_p=13 if (selfem_partner==2) & (isco08_partner >= 2200 & isco08_partner <= 2212)
replace class16_p=13 if (selfem_partner==2) & (isco08_partner == 2250)
replace class16_p=13 if (selfem_partner==2) & (isco08_partner >= 2261 & isco08_partner <= 2262)
replace class16_p=13 if (selfem_partner==2) & (isco08_partner >= 2300 & isco08_partner <= 2330)
replace class16_p=13 if (selfem_partner==2) & (isco08_partner >= 2350 & isco08_partner <= 2352)
replace class16_p=13 if (selfem_partner==2) & (isco08_partner == 2359)
replace class16_p=13 if (selfem_partner==2) & (isco08_partner == 2600)
replace class16_p=13 if (selfem_partner==2) & (isco08_partner == 2621)
replace class16_p=13 if (selfem_partner==2) & (isco08_partner == 2630)
replace class16_p=13 if (selfem_partner==2) & (isco08_partner >= 2632 & isco08_partner <= 2634)
replace class16_p=13 if (selfem_partner==2) & (isco08_partner >= 2636 & isco08_partner <= 2640)
replace class16_p=13 if (selfem_partner==2) & (isco08_partner >= 2642 & isco08_partner <= 2643)

* Socio-cultural semi-professionals (14)

replace class16_p=14 if (selfem_partner==2) & (isco08_partner == 2163)
replace class16_p=14 if (selfem_partner==2) & (isco08_partner == 2166)
replace class16_p=14 if (selfem_partner==2) & (isco08_partner >= 2220 & isco08_partner <= 2240)
replace class16_p=14 if (selfem_partner==2) & (isco08_partner == 2260)
replace class16_p=14 if (selfem_partner==2) & (isco08_partner >= 2263 & isco08_partner <= 2269)
replace class16_p=14 if (selfem_partner==2) & (isco08_partner >= 2340 & isco08_partner <= 2342)
replace class16_p=14 if (selfem_partner==2) & (isco08_partner >= 2353 & isco08_partner <= 2356)
replace class16_p=14 if (selfem_partner==2) & (isco08_partner == 2620)
replace class16_p=14 if (selfem_partner==2) & (isco08_partner == 2622)
replace class16_p=14 if (selfem_partner==2) & (isco08_partner == 2635)
replace class16_p=14 if (selfem_partner==2) & (isco08_partner == 2641)
replace class16_p=14 if (selfem_partner==2) & (isco08_partner >= 2650 & isco08_partner <= 2659)
replace class16_p=14 if (selfem_partner==2) & (isco08_partner == 3200)
replace class16_p=14 if (selfem_partner==2) & (isco08_partner >= 3220 & isco08_partner <= 3230)
replace class16_p=14 if (selfem_partner==2) & (isco08_partner == 3250)
replace class16_p=14 if (selfem_partner==2) & (isco08_partner >= 3253 & isco08_partner <= 3257)
replace class16_p=14 if (selfem_partner==2) & (isco08_partner == 3259)
replace class16_p=14 if (selfem_partner==2) & (isco08_partner >= 3400 & isco08_partner <= 3410)
replace class16_p=14 if (selfem_partner==2) & (isco08_partner >= 3412 & isco08_partner <= 3413)
replace class16_p=14 if (selfem_partner==2) & (isco08_partner >= 3430 & isco08_partner <= 3433)
replace class16_p=14 if (selfem_partner==2) & (isco08_partner == 3435)
replace class16_p=14 if (selfem_partner==2) & (isco08_partner == 4414)

* Skilled service (15)

replace class16_p=15 if (selfem_partner==2) & (isco08_partner == 3240)
replace class16_p=15 if (selfem_partner==2) & (isco08_partner == 3251)
replace class16_p=15 if (selfem_partner==2) & (isco08_partner == 3258)
replace class16_p=15 if (selfem_partner==2) & (isco08_partner >= 3420 & isco08_partner <= 3423)
replace class16_p=15 if (selfem_partner==2) & (isco08_partner == 3434)
replace class16_p=15 if (selfem_partner==2) & (isco08_partner >= 5000 & isco08_partner <= 5120)
replace class16_p=15 if (selfem_partner==2) & (isco08_partner >= 5140 & isco08_partner <= 5142)
replace class16_p=15 if (selfem_partner==2) & (isco08_partner == 5163)
replace class16_p=15 if (selfem_partner==2) & (isco08_partner == 5165)
replace class16_p=15 if (selfem_partner==2) & (isco08_partner == 5200)
replace class16_p=15 if (selfem_partner==2) & (isco08_partner == 5220)
replace class16_p=15 if (selfem_partner==2) & (isco08_partner >= 5222 & isco08_partner <= 5223)
replace class16_p=15 if (selfem_partner==2) & (isco08_partner >= 5241 & isco08_partner <= 5242)
replace class16_p=15 if (selfem_partner==2) & (isco08_partner >= 5300 & isco08_partner <= 5321)
replace class16_p=15 if (selfem_partner==2) & (isco08_partner >= 5400 & isco08_partner <= 5413)
replace class16_p=15 if (selfem_partner==2) & (isco08_partner == 5419)
replace class16_p=15 if (selfem_partner==2) & (isco08_partner == 8331)

* Low-skilled service (16)

replace class16_p=16 if (selfem_partner==2) & (isco08_partner >= 5130 & isco08_partner <= 5132)
replace class16_p=16 if (selfem_partner==2) & (isco08_partner >= 5150 & isco08_partner <= 5162)
replace class16_p=16 if (selfem_partner==2) & (isco08_partner == 5164)
replace class16_p=16 if (selfem_partner==2) & (isco08_partner == 5169)
replace class16_p=16 if (selfem_partner==2) & (isco08_partner >= 5210 & isco08_partner <= 5212)
replace class16_p=16 if (selfem_partner==2) & (isco08_partner == 5240)
replace class16_p=16 if (selfem_partner==2) & (isco08_partner >= 5243 & isco08_partner <= 5249)
replace class16_p=16 if (selfem_partner==2) & (isco08_partner >= 5322 & isco08_partner <= 5329)
replace class16_p=16 if (selfem_partner==2) & (isco08_partner == 5414)
replace class16_p=16 if (selfem_partner==2) & (isco08_partner == 8322)
replace class16_p=16 if (selfem_partner==2) & (isco08_partner >= 9100 & isco08_partner <= 9129)
replace class16_p=16 if (selfem_partner==2) & (isco08_partner >= 9400 & isco08_partner <= 9520)

mvdecode class16_p, mv(-9)
label variable class16_p "Partner's Oesch class position - 16 classes"
label define class16_p ///
1 "Large employers" ///
2 "Self-employed professionals" ///
3 "Small business owners with employees" ///
4 "Small business owners without employees" ///
5 "Technical experts" ///
6 "Technicians" ///
7 "Skilled manual" ///
8 "Low-skilled manual" ///
9 "Higher-grade managers and administrators" ///
10 "Lower-grade managers and administrators" ///
11 "Skilled clerks" ///
12 "Unskilled clerks" ///
13 "Socio-cultural professionals" ///
14 "Socio-cultural semi-professionals" ///
15 "Skilled service" ///
16 "Low-skilled service"
label value class16_p class16_p
tab class16_p

recode class16_p (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8), gen(class8_p)
label variable class8_p "Partner's Oesch class position - 8 classes"
label define class8_p ///
1 "Self-employed professionals and large employers" ///
2 "Small business owners" ///
3 "Technical (semi-)professionals" ///
4 "Production workers" ///
5 "(Associate) managers" ///
6 "Clerks" ///
7 "Socio-cultural (semi-)professionals" ///
8 "Service workers"
label value class8_p class8_p
tab class8_p

recode class16_p (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5), gen(class5_p)
label variable class5_p "Partner's Oesch class position - 5 classes"
label define  class5_p ///
1 "Higher-grade service class" ///
2 "Lower-grade service class" ///
3 "Small business owners" ///
4 "Skilled workers" ///
5 "Unskilled workers"
label value class5_p class5_p
tab class5_p

****************************************************************************************************
 * Final Oesch class position
 * Merge two class variables (respondents and partners)
 * Assign the partner's Oesch class position if the respondent's Oesch class position is missing
 ****************************************************************************************************

gen class16=class16_r
replace class16=class16_p if class16_r==.

label variable class16 "Final Oesch class position - 16 classes"
label define class16 ///
1 "Large employers" ///
2 "Self-employed professionals" ///
3 "Small business owners with employees" ///
4 "Small business owners without employees" ///
5 "Technical experts" ///
6 "Technicians" ///
7 "Skilled manual" ///
8 "Low-skilled manual" ///
9 "Higher-grade managers and administrators" ///
10 "Lower-grade managers and administrators" ///
11 "Skilled clerks" ///
12 "Unskilled clerks" ///
13 "Socio-cultural professionals" ///
14 "Socio-cultural semi-professionals" ///
15 "Skilled service" ///
16 "Low-skilled service"
label value class16 class16
tab class16

recode class16 (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8), gen(class8)
label variable class8 "Final Oesch class position - 8 classes"
label define class8 ///
1 "Self-employed professionals and large employers" ///
2 "Small business owners" ///
3 "Technical (semi-)professionals" ///
4 "Production workers" ///
5 "(Associate) managers" ///
6 "Clerks" ///
7 "Socio-cultural (semi-)professionals" ///
8 "Service workers"
label value class8 class8
tab class8

recode class16 (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5), gen(class5)
label variable class5 "Final Oesch class position - 5 classes"
label define class5 ///
1 "Higher-grade service class" ///
2 "Lower-grade service class" ///
3 "Small business owners" ///
4 "Skilled workers" ///
5 "Unskilled workers"
label value class5 class5
tab class5


drop isco08_mainjob selfem_mainjob isco08_partner selfem_partner 

save, replace




*********CLASS SCHEMA with 6 classes***********

recode class16 (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(11 12=4)(7 8=5)(15 16=6), gen(class6)
label variable class6 "Final Oesch class position - 6 classes"
label define class6 ///
1 "Upper & upper-middle class" ///
2 "Lower middle class" ///
3 "Small business owners" ///
4 "Clerks"  ///
5 "Production workers" ///
6 "Service workers"
label value class6 class6
fre class6

* class6 for Poland 1987
replace class6=1 if (PL_OCC87==1 | PL_OCC87==2) & country=="PL" & YEAR==1987
replace class6=2 if (PL_OCC87==3 | PL_OCC87==7) & country=="PL" & YEAR==1987
replace class6=3 if (PL_OCC87==6 | PL_OCC87==11) & country=="PL" & YEAR==1987 
replace class6=4 if (PL_OCC87==4) & country=="PL" & YEAR==1987
replace class6=5 if (PL_OCC87==8| PL_OCC87==9 | PL_OCC87==10| PL_OCC87==12) & country=="PL" & YEAR==1987
replace class6=6 if (PL_OCC87==5) & country=="PL" & YEAR==1987


save, replace

*******************************************************************************
*APPEND THE TWO DATASET WITH CLASS SCHEMA
*******************************************************************************

use "$path\DATASET_1987-2013_class.dta", clear
append using "$path\DATASET_2014-18_class.dta"
save "$path\DATASET_1987-2018.dta", replace




*******************************************************************************
*HARMONIZE INCOME VARIABLES
*******************************************************************************
gen income=.
label variable income "Annual household income"

*US
bys YEAR: fre INC if country=="US"
bys YEAR: fre US_INC if country=="US"
bys YEAR: fre US_INC87 if country=="US"
bys YEAR: fre US_INC92 if country=="US"
bys YEAR: fre US_INC99 if country=="US"
bys YEAR: fre US_INC09 if country=="US"

fre INC if country=="US"
fre US_INC if country=="US"
fre US_INC87 if country=="US"
fre US_INC92 if country=="US"
fre US_INC99 if country=="US"
fre US_INC09 if country=="US"

recode US_INC (999997 999998 = .)

replace income=INC if country=="US" & YEAR==2002 | YEAR==2004
replace income=US_INC if country=="US" & YEAR>=2006 | YEAR<=2018
replace income=US_INC87 if country=="US" & YEAR==1987
replace income=US_INC92 if country=="US" & YEAR==1992
replace income=US_INC99 if country=="US" & YEAR==1999
replace income=US_INC09 if country=="US" & YEAR==2010

fre income if country=="US"
bys YEAR: sum income if country=="US"

*GB
fre INC if country=="GB"
fre INCOME if country=="GB"
bys YEAR: fre GB_INC if country=="GB"
fre GB_INC87 if country=="GB"
fre GB_INC92 if country=="GB"
fre GB_INC99 if country=="GB"
fre GB_INC09 if country=="GB" & YEAR==2009

recode GB_INC (999997 999998 999999 = .)

replace GB_INC=GB_INC*12 if YEAR>=2010 | YEAR<=2017 & country=="GB"

replace income=INC if country=="GB" & (YEAR==2002 | YEAR==2004)
replace income=INCOME if country=="GB" & YEAR==2003
replace income=GB_INC if country=="GB" & (YEAR>=2005 & YEAR<=2017)
replace income=GB_INC87 if country=="GB" & YEAR==1987
replace income=GB_INC92 if country=="GB" & YEAR==1992
replace income=GB_INC99 if country=="GB" & YEAR==1999
replace income=GB_INC09 if country=="GB" & YEAR==2009

bys YEAR: sum income if country=="GB"


*CH
fre INC if country=="CH"
fre INCOME if country=="CH"
bys YEAR: fre CH_INC if country=="CH"
fre CH_INC87 if country=="CH"
fre CH_INC09 if country=="CH" & YEAR==2009

recode CH_INC (999997 999998 999999 = .)

replace income=INC if country=="CH" & YEAR==2002
replace income=INCOME if country=="CH" & YEAR==2003
replace income=CH_INC if country=="CH" & (YEAR>=2005 & YEAR<=2017)
replace income=CH_INC87 if country=="CH" & YEAR==1987
replace income=CH_INC09 if country=="CH" & YEAR==2009

replace income=income*12 if country=="CH"
bys YEAR: sum income if country=="CH"

fre income if country=="CH"


*DE
bys YEAR: fre INC if country=="DE"
bys YEAR: fre INCOME if country=="DE"
bys YEAR: fre DE_INC if country=="DE"
sum DE_INC99 if country=="DE"
fre DE_INC09 if country=="DE" & YEAR==2010

recode DE_INC (999997 999998 999999 = .)
replace DE_INC99=DE_INC99*0.511 if country=="DE" & YEAR==1999

replace income=INC if country=="DE" & (YEAR==2002 | (YEAR==2004 & INCOME>=.))
replace income=INCOME if country=="DE" & YEAR==2004 & INC>=.
replace income=DE_INC if country=="DE" & (YEAR>=2006 & YEAR<=2018)
replace income=DE_INC99 if country=="DE" & YEAR==1999
replace income=DE_INC09 if country=="DE" & YEAR==2010

replace income=income*12 if country=="DE"

bys YEAR: sum income if country=="DE"

fre income if country=="DE"

*SE
bys YEAR: fre INC if country=="SE"
bys YEAR: fre INCOME if country=="SE"
bys YEAR: fre SE_INC if country=="SE"
sum SE_INC99 if country=="SE"
fre SE_INC09 if country=="SE" & YEAR==2009

recode SE_INC (999997 999998 999999 = .)

replace income=INC if country=="SE" & (YEAR==2002 | YEAR==2004)
replace income=INCOME if country=="SE" & YEAR==2003
replace income=SE_INC if country=="SE" & (YEAR>=2005 & YEAR<=2017)
replace income=SE_INC99 if country=="SE" & YEAR==1999
replace income=SE_INC09 if country=="SE" & YEAR==2009

replace income=income*12 if country=="SE"

bys YEAR: sum income if country=="SE"

fre income if country=="SE"


*NO
bys YEAR: fre INC if country=="NO"
bys YEAR: fre INCOME if country=="NO"
bys YEAR: fre NO_INC if country=="NO"
fre NO_INC92 if country=="NO"
fre NO_INC99 if country=="NO"
fre NO_INC09 if country=="NO" & YEAR==2009

recode NO_INC (9999997 9999998 9999999 99999999 = .)

replace income=INC if country=="NO" & (YEAR==2002 | YEAR==2004)
replace income=INCOME if country=="NO" & YEAR==2003
replace income=NO_INC if country=="NO" & (YEAR>=2005 & YEAR<=2017)
replace income=NO_INC92 if country=="NO" & YEAR==1992
replace income=NO_INC99 if country=="NO" & YEAR==1999
replace income=NO_INC09 if country=="NO" & YEAR==2009

*it seems that thre 0 are missing in 2003 and 2005. In the questionnaire it seems that they asked to fill the income without the last three 000:
replace income=income*1000 if country=="NO" & (YEAR==2003 | YEAR==2005)
bys YEAR: sum income if country=="NO"

fre income if country=="NO"

*PL
bys YEAR: fre INC if country=="PL"
bys YEAR: fre PL_INC if country=="PL"
fre PL_INC92 if country=="PL"
fre PL_INC99 if country=="PL"
bys YEAR: fre PL_INC09 if country=="PL"

recode PL_INC (9999997 999998 999999 99999999 = .)
replace PL_INC92=PL_INC92/10000 if country=="PL" & YEAR==1992

replace income=INC if country=="PL" & (YEAR==2002 | YEAR==2005)
replace income=PL_INC if country=="PL" & (YEAR==2008 |YEAR==2013 | YEAR==2015)
replace income=PL_INC92 if country=="PL" & YEAR==1992
replace income=PL_INC99 if country=="PL" & YEAR==1999
replace income=PL_INC09 if country=="PL" & YEAR==2010

replace income=income*12 if country=="PL"
bys YEAR: sum income if country=="PL"

fre income if country=="PL"

*HU
bys YEAR: sum INC if country=="HU"
bys YEAR: fre INCOME if country=="HU"
bys YEAR: fre HU_INC if country=="HU"
fre HU_INC if country=="HU" & YEAR==2006
fre HU_INC87 if country=="HU"
fre HU_INC92 if country=="HU"
fre HU_INC99 if country=="HU"
bys YEAR: fre HU_INC09 if country=="HU"

recode HU_INC (9999997 9999998 9999999 = .)

replace income=INC if country=="HU" & (YEAR==2002 | YEAR==2004)
replace income=INCOME if country=="HU" & (YEAR==2003)
replace income=HU_INC if country=="HU" & (YEAR>=2005 & YEAR<=2017)
replace income=HU_INC87 if country=="HU" & YEAR==1987
replace income=HU_INC92 if country=="HU" & YEAR==1992
replace income=HU_INC99 if country=="HU" & YEAR==1999
replace income=HU_INC09 if country=="HU" & YEAR==2009

replace income=income*12 if country=="HU"
bys YEAR: sum income if country=="HU"
*NB non trustworthy years: 1987, 2006


save "$path\DATASET_1987-2018.dta", replace


********************************************************************************
*drop repeated samples and attribute the years corresponding to data collection
********************************************************************************

*SWITWERLAND
drop if country=="CH" & (YEAR==2004 | YEAR==2006 | YEAR==2008 | YEAR==2010 | YEAR==2012 | YEAR==2014 | YEAR==2016)

*POLAND
drop if country=="PL" & (YEAR==2003 | YEAR==2006 | YEAR==2008 | YEAR==2011 | YEAR==2014)
rename YEAR year_original
gen YEAR_RECODED=year_original
recode YEAR (2004=2005) (2007=2008) (2009=2010) (2012=2013) if country=="PL"

*US
drop if country=="US" &  (YEAR==2003| YEAR==2005)
recode YEAR (2009=2010) (2013=2014) (2015=2016) (2017=2018) if country=="US"

*GERMANY
recode YEAR (2003=2004) (2005=2006) (2007=2008) (2009=2010) (2011=2012) (2013=2014) (2015=2016) (2017=2018) if country=="DE"

*AUSTRALIA
recode YEAR (2004=2005) (2008=2009) (2010=2012) (2011=2012) (2012=2013) if COUNTRY==36

*AUSTRIA
drop if COUNTRY==40 &  (YEAR==2003| YEAR==2007 | YEAR==2009)
recode YEAR (2012=2013) (2014=2015) (2017=2018) if COUNTRY==40

*SLOVENIA
drop if COUNTRY==705 & (YEAR==2008| YEAR==2010 | YEAR==2015)
recode YEAR (2002=2003) (2014=2013) if COUNTRY==705

*CZECH REPUBLIC
drop if COUNTRY==203 & (YEAR==2011)

*SLOVAKIAN REPUBLIC
drop if COUNTRY==703 & (YEAR==2007| YEAR==2010 | YEAR==2011)
recode YEAR (2004=2005)(2003=2004)  if COUNTRY==703


save "$path\DATASET_1987-2018_ready.dta", replace





********************************************************************************
*********************NEW DATASET************************************************
*class schema without using partner's information
********************************************************************************

*armonisation of the labels of the values of YEAR:

use "$path\DATASET_1987-2018.dta", clear
drop class16_r selfemp_r class8_r class5_r class16 class8 class5 class6 GB87_class GB92_class SE92_class US87_class IT87_class5 IT87_class8 IT92_class8 IT92_class5 emplno_r

save "$path\DATASET_1987-2018_classnopart.dta", replace

keep if YEAR<2014
save "$path\DATASET_1987-2013_classnopart.dta", replace
use "$path\DATASET_1987-2013_classnopart.dta", clear


* Create 16-Class schema, 8-Class schema and 5-Class schema
* Data: ISSP cumulative dataset Social Inequalities (1987, 1992, 1999, 2009), annual datasets 1997-2013 (containing ISCO88 codes)
*******************************************************************************
	
*******************************************************************************
* Respondent's Oesch class position
* Recode and create variables used to construct class variable for respondents
* Variables used to construct class variable for respondents: ISCO88, NEMPLOY, SELFEMP, EMPREL, WRKTYPE
* If using a cumulation of annual datasets including 2000 and 2010, it is also necessary to generate a YEAR variable
*******************************************************************************

**** Recode occupation variable (isco88 com 4-digit) for respondents

tab ISCO88, m
 
recode ISCO88 (missing=-9), copyrest gen(isco88_mainjob)
recode isco88_mainjob (0=-9)
label variable isco88_mainjob "Current occupation of respondent - isco88 4-digit"
tab isco88_mainjob

 
**** Recode employment status for respondents
 
recode NEMPLOY (9995=0)(1/9=1)(10/9990=2)(.=.) (.a=.) (.n=.) (9997=.) (9998=.) (9999=.), gen(emplno_r)
recode emplno_r (0=2) if NEMPLOY==9995 & YEAR==2010
recode emplno_r (99996=0) if NEMPLOY==99996 & YEAR==2000
label define emplno_r ///
0 "0 employees" ///
1 "1-9 employees" ///
2 "10+ employees"
label value emplno_r emplno_r
tab emplno_r
***NB: In 2002, 2003 and 2007 it is not possible to identify self-employed respondents with no emoloyee: in these years there is no "0" nor corresponding value in the variable "NEMPLOY". Moreover, in these years there is no variable distinguishing between self-employed with emoloyees and self-employed without employees.
				
				
gen selfemp_r=9
replace selfemp_r=1 if emplno_r==1 | emplno_r==2 | SELFEMP==1
replace selfemp_r=2 if SELFEMP==2 
replace selfemp_r=1 if emplno_r==1 | emplno_r==2 | WRKTYPE==4 
replace selfemp_r=2 if WRKTYPE==1| WRKTYPE==2 | WRKTYPE==3 | WRKTYPE==5 | WRKTYPE==6 
replace selfemp_r=1 if emplno_r==1 | emplno_r==2 |  EMPREL==2 | EMPREL==3 | EMPREL==4
replace selfemp_r=2 if EMPREL==1
	
label define selfemp_r 1"Self-employed" 2 "Employee" 9 "Missing"
label value selfemp_r selfemp_r			
tab selfemp_r

gen selfem_mainjob=.
replace selfem_mainjob=1 if selfemp_r==2 | selfemp_r==9
replace selfem_mainjob=2 if selfemp_r==1 & (emplno_r==0 | emplno_r==.)
replace selfem_mainjob=2 if EMPREL==2 | EMPREL==4
	
replace selfem_mainjob=3 if (selfemp_r==1 | selfemp_r==9) & emplno_r==1 
replace selfem_mainjob=4 if (selfemp_r==1 | selfemp_r==9) & emplno_r==2
label variable selfem_mainjob "Employment status for respondents"
label define selfem_mainjob 1 "Not self-employed" 2 "Self-empl without employees" 3 "Self-empl with 1-9 employees" 4 "Self-empl with 10 or more" 
label value selfem_mainjob selfem_mainjob
tab selfem_mainjob, m
                                 
***NB1: selfem_mainjob=1 if selfemp_r==9 -> people we don't know if they are self-employed or not are considered to be employees.
***NB2: selfem_mainjob=2 selfemp_r==1 & emplno_r==. -> self-employed people we don't know how many employees they have are considered to be self-employed without employees.


*************************************************
* Create Oesch class schema for respondents
* Create class16_r class8_r class5_r
* Using isco88_mainjob and selfem_mainjob
*************************************************

gen class16_r = -9
 
* Large employers (1)
 
replace class16_r=1 if selfem_mainjob==4
 
* Self-employed professionals (2)
 
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco88_mainjob >= 2000 & isco88_mainjob <= 2229) 
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco88_mainjob >= 2300 & isco88_mainjob <= 2470)

* Small business owners with employees (3)
 
replace class16_r=3 if (selfem_mainjob==3) & (isco88_mainjob >= 1000 & isco88_mainjob <= 1999)
replace class16_r=3 if (selfem_mainjob==3) & (isco88_mainjob >= 3000 & isco88_mainjob <= 9333)
replace class16_r=3 if (selfem_mainjob==3) & (isco88_mainjob == 2230)

* Small business owners without employees (4)
 
replace class16_r=4 if (selfem_mainjob==2) & (isco88_mainjob >= 1000 & isco88_mainjob <= 1999)
replace class16_r=4 if (selfem_mainjob==2) & (isco88_mainjob >= 3000 & isco88_mainjob <= 9333)
replace class16_r=4 if (selfem_mainjob==2) & (isco88_mainjob == 2230)
 

* Technical experts (5)
 
replace class16_r=5 if (selfem_mainjob==1) & (isco88_mainjob >= 2000 & isco88_mainjob <= 2213)

* Technicians (6)
 
replace class16_r=6 if (selfem_mainjob==1) & (isco88_mainjob >= 3000 & isco88_mainjob <= 3152)
replace class16_r=6 if (selfem_mainjob==1) & (isco88_mainjob >= 3210 & isco88_mainjob <= 3213)
replace class16_r=6 if (selfem_mainjob==1) & (isco88_mainjob == 3434)
replace class16_r=6 if (selfem_mainjob==1) & (isco88_mainjob == 7900)

* Skilled manual (7)

replace class16_r=7 if (selfem_mainjob==1) & (isco88_mainjob >= 6000 & isco88_mainjob <= 7450)
replace class16_r=7 if (selfem_mainjob==1) & (isco88_mainjob >= 7500 & isco88_mainjob <= 7510)
replace class16_r=7 if (selfem_mainjob==1) & (isco88_mainjob >= 8310 & isco88_mainjob <= 8312)
replace class16_r=7 if (selfem_mainjob==1) & (isco88_mainjob >= 8324 & isco88_mainjob <= 8330)
replace class16_r=7 if (selfem_mainjob==1) & (isco88_mainjob >= 8332 & isco88_mainjob <= 8340)
replace class16_r=7 if (selfem_mainjob==1) & (isco88_mainjob == 7520)
replace class16_r=7 if (selfem_mainjob==1) & (isco88_mainjob == 8341)

* Low-skilled manual (8)
 
replace class16_r=8 if (selfem_mainjob==1) & (isco88_mainjob >= 8000 & isco88_mainjob <= 8300)
replace class16_r=8 if (selfem_mainjob==1) & (isco88_mainjob >= 8320 & isco88_mainjob <= 8321)
replace class16_r=8 if (selfem_mainjob==1) & (isco88_mainjob == 8331)
replace class16_r=8 if (selfem_mainjob==1) & (isco88_mainjob >= 9153 & isco88_mainjob <= 9333)
replace class16_r=8 if (selfem_mainjob==1) & (isco88_mainjob == 8400)
replace class16_r=8 if (selfem_mainjob==1) & (isco88_mainjob == 7530)


* Higher-grade managers and administrators (9)
 
replace class16_r=9 if (selfem_mainjob==1) & (isco88_mainjob >= 1000 & isco88_mainjob <= 1239)
replace class16_r=9 if (selfem_mainjob==1) & (isco88_mainjob >= 2400 & isco88_mainjob <= 2429)
replace class16_r=9 if (selfem_mainjob==1) & (isco88_mainjob == 2441)
replace class16_r=9 if (selfem_mainjob==1) & (isco88_mainjob == 2470)

* Lower-grade managers and administrators (10) - "new" code ISCO (3439)

replace class16_r=10 if (selfem_mainjob==1) & (isco88_mainjob >= 1300 & isco88_mainjob <= 1412)
replace class16_r=10 if (selfem_mainjob==1) & (isco88_mainjob >= 3400 & isco88_mainjob <= 3433)
replace class16_r=10 if (selfem_mainjob==1) & (isco88_mainjob >= 3439 & isco88_mainjob <= 3451)
replace class16_r=10 if (selfem_mainjob==1) & (isco88_mainjob >= 1240 & isco88_mainjob <= 1252)
replace class16_r=10 if (selfem_mainjob==1) & (isco88_mainjob ==1252)


* Skilled clerks (11)

replace class16_r=11 if (selfem_mainjob==1) & (isco88_mainjob >= 4000 & isco88_mainjob <= 4112)
replace class16_r=11 if (selfem_mainjob==1) & (isco88_mainjob >= 4114 & isco88_mainjob <= 4210)
replace class16_r=11 if (selfem_mainjob==1) & (isco88_mainjob >= 4212 & isco88_mainjob <= 4222)

* Unskilled clerks (12)

replace class16_r=12 if (selfem_mainjob==1) & (isco88_mainjob == 4113)
replace class16_r=12 if (selfem_mainjob==1) & (isco88_mainjob == 4211)
replace class16_r=12 if (selfem_mainjob==1) & (isco88_mainjob == 4223)

* Socio-cultural professionals (13)
 
replace class16_r=13 if (selfem_mainjob==1) & (isco88_mainjob >= 2220 &  isco88_mainjob <= 2229)
replace class16_r=13 if (selfem_mainjob==1) & (isco88_mainjob >= 2300 &  isco88_mainjob <= 2323)
replace class16_r=13 if (selfem_mainjob==1) & (isco88_mainjob >= 2340 &  isco88_mainjob <= 2359)
replace class16_r=13 if (selfem_mainjob==1) & (isco88_mainjob >= 2430 &  isco88_mainjob <= 2440)
replace class16_r=13 if (selfem_mainjob==1) & (isco88_mainjob >= 2442 &  isco88_mainjob <= 2443)
replace class16_r=13 if (selfem_mainjob==1) & (isco88_mainjob == 2445)
replace class16_r=13 if (selfem_mainjob==1) & (isco88_mainjob == 2451)
replace class16_r=13 if (selfem_mainjob==1) & (isco88_mainjob == 2460)
replace class16_r=13 if (selfem_mainjob==1) & (isco88_mainjob == 3491)
replace class16_r=13 if (selfem_mainjob==1) & (isco88_mainjob == 3492)

* Socio-cultural semi-professionals (14)
 
replace class16_r=14 if (selfem_mainjob==1) & (isco88_mainjob == 2230)
replace class16_r=14 if (selfem_mainjob==1) & (isco88_mainjob >= 2330 & isco88_mainjob <= 2332)
replace class16_r=14 if (selfem_mainjob==1) & (isco88_mainjob == 2444)
replace class16_r=14 if (selfem_mainjob==1) & (isco88_mainjob >= 2446 & isco88_mainjob <= 2450)
replace class16_r=14 if (selfem_mainjob==1) & (isco88_mainjob >= 2452 & isco88_mainjob <= 2455)
replace class16_r=14 if (selfem_mainjob==1) & (isco88_mainjob == 3200)
replace class16_r=14 if (selfem_mainjob==1) & (isco88_mainjob >= 3220 & isco88_mainjob <= 3224)
replace class16_r=14 if (selfem_mainjob==1) & (isco88_mainjob == 3226)
replace class16_r=14 if (selfem_mainjob==1) & (isco88_mainjob >= 3229 & isco88_mainjob <= 3342)
replace class16_r=14 if (selfem_mainjob==1) & (isco88_mainjob >= 3460 & isco88_mainjob <= 3472)
replace class16_r=14 if (selfem_mainjob==1) & (isco88_mainjob == 3480)
replace class16_r=14 if (selfem_mainjob==1) & (isco88_mainjob >=2500 & isco88_mainjob<=2519)


* Skilled service (15)

replace class16_r=15 if (selfem_mainjob==1) & (isco88_mainjob == 3225)
replace class16_r=15 if (selfem_mainjob==1) & (isco88_mainjob >= 3227 & isco88_mainjob <= 3228)
replace class16_r=15 if (selfem_mainjob==1) & (isco88_mainjob >= 3473 & isco88_mainjob <= 3475)
replace class16_r=15 if (selfem_mainjob==1) & (isco88_mainjob >= 5000 & isco88_mainjob <= 5113)
replace class16_r=15 if (selfem_mainjob==1) & (isco88_mainjob == 5122)
replace class16_r=15 if (selfem_mainjob==1) & (isco88_mainjob >= 5131 & isco88_mainjob <= 5132)
replace class16_r=15 if (selfem_mainjob==1) & (isco88_mainjob >= 5140 & isco88_mainjob <= 5141)
replace class16_r=15 if (selfem_mainjob==1) & (isco88_mainjob == 5143)
replace class16_r=15 if (selfem_mainjob==1) & (isco88_mainjob >= 5160 & isco88_mainjob <= 5223)
replace class16_r=15 if (selfem_mainjob==1) & (isco88_mainjob == 8323)

* Low-skilled service (16)
 
replace class16_r=16 if (selfem_mainjob==1) & (isco88_mainjob >= 5120 & isco88_mainjob <= 5121)
replace class16_r=16 if (selfem_mainjob==1) & (isco88_mainjob >= 5123 & isco88_mainjob <= 5130)
replace class16_r=16 if (selfem_mainjob==1) & (isco88_mainjob >= 5133 & isco88_mainjob <= 5139)
replace class16_r=16 if (selfem_mainjob==1) & (isco88_mainjob == 5142)
replace class16_r=16 if (selfem_mainjob==1) & (isco88_mainjob == 5149)
replace class16_r=16 if (selfem_mainjob==1) & (isco88_mainjob == 5150)
replace class16_r=16 if (selfem_mainjob==1) & (isco88_mainjob == 5151)
replace class16_r=16 if (selfem_mainjob==1) & (isco88_mainjob == 5152)
replace class16_r=16 if (selfem_mainjob==1) & (isco88_mainjob == 5230)
replace class16_r=16 if (selfem_mainjob==1) & (isco88_mainjob == 8322)
replace class16_r=16 if (selfem_mainjob==1) & (isco88_mainjob >= 9000 & isco88_mainjob <= 9152)


***NB: a missing value in class16_r when isco88_mainjob!=. means that the value of selfem_mainjob was not coherent with the job type


mvdecode class16_r, mv(-9)
label variable class16_r "Respondent's Oesch class position - 16 classes"
label define class16_r ///
1 "Large employers" ///
2 "Self-employed professionals" ///
3 "Small business owners with employees" ///
4 "Small business owners without employees" ///
5 "Technical experts" ///
6 "Technicians" ///
7 "Skilled manual" ///
8 "Low-skilled manual" ///
9 "Higher-grade managers and administrators" ///
10 "Lower-grade managers and administrators" ///
11 "Skilled clerks" ///
12 "Unskilled clerks" ///
13 "Socio-cultural professionals" ///
14 "Socio-cultural semi-professionals" ///
15 "Skilled service" ///
16 "Low-skilled service"
label value class16_r class16_r
tab class16_r
 
recode class16_r (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8), gen(class8_r)
label variable class8_r "Respondent's Oesch class position - 8 classes"
label define class8_r ///
1 "Self-employed professionals and large employers" ///
2 "Small business owners" ///
3 "Technical (semi-)professionals" ///
4 "Production workers" ///
5 "(Associate) managers" ///
6 "Clerks" ///
7 "Socio-cultural (semi-)professionals" ///
8 "Service workers"
label value class8_r class8_r
tab class8_r

recode class16_r (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5), gen(class5_r)
label variable class5_r "Respondent's Oesch class position - 5 classes"
label define  class5_r ///
1 "Higher-grade service class" ///
2 "Lower-grade service class" ///
3 "Small business owners" ///
4 "Skilled workers" ///
5 "Unskilled workers"
label value class5_r class5_r
tab class5_r


*******************************************************************************
 * Final Oesch class position
*******************************************************************************

gen class16=class16_r

label variable class16 "Final Oesch class position - 16 classes"
label define class16 ///
1 "Large employers" ///
2 "Self-employed professionals" ///
3 "Small business owners with employees" ///
4 "Small business owners without employees" ///
5 "Technical experts" ///
6 "Technicians" ///
7 "Skilled manual" ///
8 "Low-skilled manual" ///
9 "Higher-grade managers and administrators" ///
10 "Lower-grade managers and administrators" ///
11 "Skilled clerks" ///
12 "Unskilled clerks" ///
13 "Socio-cultural professionals" ///
14 "Socio-cultural semi-professionals" ///
15 "Skilled service" ///
16 "Low-skilled service"
label value class16 class16
tab class16

recode class16 (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8), gen(class8)
label variable class8 "Final Oesch class position - 8 classes"
label define class8 ///
1 "Self-employed professionals and large employers" ///
2 "Small business owners" ///
3 "Technical (semi-)professionals" ///
4 "Production workers" ///
5 "(Associate) managers" ///
6 "Clerks" ///
7 "Socio-cultural (semi-)professionals" ///
8 "Service workers"
label value class8 class8
tab class8

recode class16 (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5), gen(class5)
label variable class5 "Final Oesch class position - 5 classes"
label define class5 ///
1 "Higher-grade service class" ///
2 "Lower-grade service class" ///
3 "Small business owners" ///
4 "Skilled workers" ///
5 "Unskilled workers"
label value class5 class5
tab class5


drop isco88_mainjob emplno_r selfem_mainjob

	
*******************************************************************************
* SPECIFIC Oesch’s class schema for Great Britain 1987 
*******************************************************************************

*************************************************
* Create Oesch class schema for respondent
* Create GB87_class
* Using GB_OCC87 and SELFEMP
*************************************************

*Class schema for respondent

gen GB87_class=.

* Large employers (1)
replace GB87_class=1 if SELFEMP==1 & GB_OCC87==3
replace GB87_class=1 if SELFEMP==1 & GB_OCC87==5
replace GB87_class=1 if SELFEMP==1 & GB_OCC87==7
replace GB87_class=1 if SELFEMP==1 & GB_OCC87==9
replace GB87_class=1 if SELFEMP==1 & GB_OCC87==34
replace GB87_class=1 if SELFEMP==1 & GB_OCC87==36
replace GB87_class=1 if SELFEMP==1 & GB_OCC87==38
replace GB87_class=1 if SELFEMP==1 & GB_OCC87==44


****NB: no good differenciation possible between (1) and (3)

* Self-employed professionals (2)
replace GB87_class=2 if SELFEMP==1 & GB_OCC87==1
replace GB87_class=2 if SELFEMP==1 & GB_OCC87==2
replace GB87_class=2 if SELFEMP==1 & GB_OCC87==4
replace GB87_class=2 if SELFEMP==1 & GB_OCC87>=10 & GB_OCC87<=21 
replace GB87_class=2 if SELFEMP==1 & GB_OCC87>=24 & GB_OCC87<=33


* Small business owners with employees (3)
replace GB87_class=3 if SELFEMP==1 & GB_OCC87==35
replace GB87_class=3 if SELFEMP==1 & GB_OCC87==37
replace GB87_class=3 if SELFEMP==1 & GB_OCC87==39

* Small business owners without employees (4)
replace GB87_class=4 if SELFEMP==1 & GB_OCC87==6
replace GB87_class=4 if SELFEMP==1 & GB_OCC87==22
replace GB87_class=4 if SELFEMP==1 & GB_OCC87==32
replace GB87_class=4 if SELFEMP==1 & GB_OCC87==40
replace GB87_class=4 if SELFEMP==1 & GB_OCC87==43
replace GB87_class=4 if SELFEMP==1 & GB_OCC87>=45 & GB_OCC87<=998

* Technical experts (5)
replace GB87_class=5 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==4
replace GB87_class=5 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=24 & GB_OCC87<=28
replace GB87_class=5 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==30
replace GB87_class=5 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==31
replace GB87_class=5 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==33

* Technicians (6)
replace GB87_class=6 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==6
replace GB87_class=6 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==22
replace GB87_class=6 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==32

* Skilled manual (7)
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==63
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==76
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==78
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==79
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==85
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==87
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=90 & GB_OCC87<=95
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==102
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==111
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==114
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==115
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=118 & GB_OCC87<=128
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==130
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==132
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==133
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==139
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==140
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==143
replace GB87_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==998

* Low-skilled manual (8)

replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==40
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==77
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==80
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==83
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==89
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=97 & GB_OCC87<=101
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=105 & GB_OCC8<=110
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==112
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==113
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==117
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==129
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==131
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=134 & GB_OCC87<=138
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==141
replace GB87_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=144 & GB_OCC87<=161

* Higher-grade managers and administrators (9)

replace GB87_class=9 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=1 & GB_OCC87<=3
replace GB87_class=9 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==5
replace GB87_class=9 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==7
replace GB87_class=9 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==9
replace GB87_class=9 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=34 & GB_OCC87<=36
replace GB87_class=9 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==44

* Lower-grade managers and administrators (10)

replace GB87_class=10 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=37 & GB_OCC87<=39
replace GB87_class=10 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==57
replace GB87_class=10 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==60


***NB: no good differenciation possible between (9) and (10) for manager of "small" entreprises


* Skilled clerks (11)
replace GB87_class=11 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=45 & GB_OCC87<=46
replace GB87_class=11 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=48 & GB_OCC87<=50
replace GB87_class=11 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=53 & GB_OCC87<=54

* Unskilled clerks (12)

replace GB87_class=12 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==51
replace GB87_class=12 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==47


* Socio-cultural professionals (13)

replace GB87_class=13 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=10 & GB_OCC87<=11
replace GB87_class=13 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=13 & GB_OCC87<=19


* Socio-cultural semi-professionals (14)

replace GB87_class=14 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==12
replace GB87_class=14 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==20
replace GB87_class=14 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==21
replace GB87_class=14 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==29

* Skilled service (15)

replace GB87_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==43
replace GB87_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==55
replace GB87_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==56
replace GB87_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==61
replace GB87_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==62
replace GB87_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==64
replace GB87_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==74


* Low-skilled service (16)
replace GB87_class=16 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87>=65 & GB_OCC87<=72
replace GB87_class=16 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC87==75


* Not classifiable (0): military + "other occupation"

replace GB87_class=0 if GB_OCC87==41
replace GB87_class=0 if GB_OCC87==458

replace GB87_class=. if GB_OCC87==.i
replace GB87_class=. if GB_OCC87==.n


tab GB87_class if COUNTRY==82601 & YEAR==1987, m


*********************************************************
* Recode class16_r, class16_p, class8_r, class8_p, class5_r, class5_p
* Recode class16, class8, class5
* for Great Britain 1987
*********************************************************

replace class16_r=GB87_class if COUNTRY==82601 & YEAR==1987

recode class16_r (0=.)


replace class8_r=class16_r if COUNTRY==82601 & YEAR==1987
recode class8_r (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8) if COUNTRY==82601 & YEAR==1987


replace class5_r=class16_r if COUNTRY==82601 & YEAR==1987
recode class5_r (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5) if COUNTRY==82601 & YEAR==1987


replace class16=class16_r if COUNTRY==82601 & YEAR==1987

replace class8=class16 if COUNTRY==82601 & YEAR==1987
recode class8 (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8) if COUNTRY==82601 & YEAR==1987

replace class5=class16 if COUNTRY==82601 & YEAR==1987
recode class5 (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5) if COUNTRY==82601 & YEAR==1987


*******************************************************************************
* SPECIFIC Oesch’s class schema for Great Britain 1992 
*******************************************************************************

*************************************************
* Create Oesch class schema for respondent
* Create GB92_class
* Using GB_OCC92 and SELFEMP
*************************************************

***CLASSES FOR GB 1992
gen GB92_class=.

* Large employers (1)
replace GB92_class=1 if SELFEMP==1 & GB_OCC92>=10 & GB_OCC92<=19

***NB: no good differenciation possible between (1) and (3)

* Self-employed professionals (2)
replace GB92_class=2 if SELFEMP==1 & GB_OCC92>=20 & GB_OCC92<=29
replace GB92_class=2 if SELFEMP==1 & GB_OCC92>=31 & GB_OCC92<=32
replace GB92_class=2 if SELFEMP==1 & GB_OCC92>=34 & GB_OCC92<=37

* Small business owners with employees (3)
replace GB92_class=3 if SELFEMP==1 & GB_OCC92==94

* Small business owners without employees (4)
replace GB92_class=4 if SELFEMP==1 & GB_OCC92==30
replace GB92_class=4 if SELFEMP==1 & GB_OCC92==33
replace GB92_class=4 if SELFEMP==1 & GB_OCC92>=38 & GB_OCC92<=93
replace GB92_class=4 if SELFEMP==1 & GB_OCC92==95

* Technical experts (5)
replace GB92_class=5 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=20 & GB_OCC92<=21
replace GB92_class=5 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==26

* Technicians (6)
replace GB92_class=6 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==30
replace GB92_class=6 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==33

* Skilled manual (7)
replace GB92_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=50 & GB_OCC92<=59
replace GB92_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==80
replace GB92_class=7 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==90

* Low-skilled manual (8)

replace GB92_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=81 & GB_OCC92<=89
replace GB92_class=8 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=91 & GB_OCC92<=93

* Higher-grade managers and administrators (9)

replace GB92_class=9 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=10 & GB_OCC92<=19
replace GB92_class=9 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=24 & GB_OCC92<=25
replace GB92_class=9 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==29
replace GB92_class=9 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=31 & GB_OCC92<=32
replace GB92_class=9 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=35 & GB_OCC92<=36

* Lower-grade managers and administrators (10)

replace GB92_class=10 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==39
replace GB92_class=10 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==94
replace GB92_class=10 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==15
replace GB92_class=10 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==70
replace GB92_class=10 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==71
replace GB92_class=10 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==94

****NB: no good differenciation possible between (9) and (10) for manager of "small" entreprises

* Skilled clerks (11)
replace GB92_class=11 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==40
replace GB92_class=11 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=42 & GB_OCC92<=45
replace GB92_class=11 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=47 & GB_OCC92<=49


* Unskilled clerks (12)

replace GB92_class=12 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==41
replace GB92_class=12 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==46


* Socio-cultural professionals (13)

replace GB92_class=13 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=22 & GB_OCC92<=23
replace GB92_class=13 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==27
replace GB92_class=13 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==34
replace GB92_class=13 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==64

* Socio-cultural semi-professionals (14)

replace GB92_class=14 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=37 & GB_OCC92<=38
replace GB92_class=14 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=22 & GB_OCC92<=23

* Skilled service (15)

replace GB92_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==61
replace GB92_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==63
replace GB92_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==69
replace GB92_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=65 & GB_OCC92<=66
replace GB92_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92>=72 & GB_OCC92<=79
replace GB92_class=15 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==95

* Low-skilled service (16)
replace GB92_class=16 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==62
replace GB92_class=16 if (SELFEMP==2 | SELFEMP==.a) & GB_OCC92==67

* Not classifiable (0): military + "other occupation"

replace GB92_class=0 if GB_OCC92==99
replace GB92_class=0 if GB_OCC92==60

replace GB92_class=. if GB_OCC92==.n


tab GB92_class if COUNTRY==82601 & YEAR==1992, m


*********************************************************
* Recode class16_r, class16_p, class8_r, class8_p, class5_r, class5_p
* Recode class16, class8, class5
* for Great Britain 1992
*********************************************************

replace class16_r=GB92_class if COUNTRY==82601 & YEAR==1992
recode class16_r (0=.)

replace class8_r=class16_r if COUNTRY==82601 & YEAR==1992
recode class8_r (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8) if COUNTRY==82601 & YEAR==1992

replace class5_r=class16_r if COUNTRY==82601 & YEAR==1992
recode class5_r (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5) if COUNTRY==82601 & YEAR==1992

replace class16=class16_r if COUNTRY==82601 & YEAR==1992

replace class8=class16 if COUNTRY==82601 & YEAR==1992
recode class8 (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8) if COUNTRY==82601 & YEAR==1992

replace class5=class16 if COUNTRY==82601 & YEAR==1992
recode class5 (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5) if COUNTRY==82601 & YEAR==1992



*******************************************************************************
* SPECIFIC Oesch’s class schema for Sweden 1992 
*******************************************************************************

*************************************************
* Create Oesch class schema for respondent
* Create SE92_class
* Using SE_OCC92 and SELFEMP
*************************************************

gen SE92_class=.

* Large employers (1)
replace SE92_class=1 if SELFEMP==1 & SE_OCC92==221
replace SE92_class=1 if SELFEMP==1 & SE_OCC92==232

****NB: no good differenciation possible between (1) and (3)

* Self-employed professionals (2)
replace SE92_class=2 if SELFEMP==1 & SE_OCC92
replace SE92_class=2 if SELFEMP==1 & SE_OCC92>=1 & SE_OCC92<=8
replace SE92_class=2 if SELFEMP==1 & SE_OCC92>=15 & SE_OCC92<=71
replace SE92_class=2 if SELFEMP==1 & SE_OCC92>=76 & SE_OCC92<=104
replace SE92_class=2 if SELFEMP==1 & SE_OCC92>=106 & SE_OCC92<=131
replace SE92_class=2 if SELFEMP==1 & SE_OCC92==155
replace SE92_class=2 if SELFEMP==1 & SE_OCC92==191
replace SE92_class=2 if SELFEMP==1 & SE_OCC92==219
replace SE92_class=2 if SELFEMP==1 & SE_OCC92>=251 & SE_OCC92<=261

* Small business owners with employees (3)
replace SE92_class=3 if SELFEMP==1 & SE_OCC92==152
replace SE92_class=3 if SELFEMP==1 & SE_OCC92>=201 & SE_OCC92<=212
replace SE92_class=3 if SELFEMP==1 & SE_OCC92==297
replace SE92_class=3 if SE_OCC92==331
replace SE92_class=3 if SE_OCC92==400
replace SE92_class=3 if SELFEMP==1 & SE_OCC92==404

* Small business owners without employees (4)
replace SE92_class=4 if SELFEMP==1 & SE_OCC92>=9 & SE_OCC92<=13
replace SE92_class=4 if SELFEMP==1 & SE_OCC92==74
replace SE92_class=4 if SELFEMP==1 & SE_OCC92==105
replace SE92_class=4 if SELFEMP==1 & SE_OCC92==139
replace SE92_class=4 if SELFEMP==1 & SE_OCC92==151
replace SE92_class=4 if SELFEMP==1 & SE_OCC92==154
replace SE92_class=4 if SELFEMP==1 & SE_OCC92>=159 & SE_OCC92<=169
replace SE92_class=4 if SELFEMP==1 & SE_OCC92>=241 & SE_OCC92<=249
replace SE92_class=4 if SELFEMP==1 & SE_OCC92>=291 & SE_OCC92<=296
replace SE92_class=4 if SELFEMP==1 & SE_OCC92>=299 & SE_OCC92<=321
replace SE92_class=4 if SELFEMP==1 & SE_OCC92>=332 & SE_OCC92<=339
replace SE92_class=4 if SELFEMP==411 & SE_OCC92>=9 & SE_OCC92<=981

* Technical experts (5)
replace SE92_class=5 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=1 & SE_OCC92<=8
replace SE92_class=5 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=15 & SE_OCC92<=22
replace SE92_class=5 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==101
replace SE92_class=5 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==251
replace SE92_class=5 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==252

* Technicians (6)
replace SE92_class=6 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=9 & SE_OCC92<=13
replace SE92_class=6 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==74
replace SE92_class=6 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==105
replace SE92_class=6 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==162
replace SE92_class=6 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==231
replace SE92_class=6 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==621

* Skilled manual (7)
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==412
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==441
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==611
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==631
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==641
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==652
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==716
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==741
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==744
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==752
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==754
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==755
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==756
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==761
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==764
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==765
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=781 & SE_OCC92<=796
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==801
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==802
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==805
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=819 & SE_OCC92<=829
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==661
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==661
replace SE92_class=7 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==912

* Low-skilled manual (8)
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==411
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==413
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==414
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==664
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==669
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=733 & SE_OCC92<=739
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==749
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==751
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==753
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==759
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==763
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==772
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==777
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==799
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==803
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==809
replace SE92_class=8 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=831 & SE_OCC92<=882

* Higher-grade managers and administrators (9)
replace SE92_class=9 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==53
replace SE92_class=9 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==152
replace SE92_class=9 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=201 & SE_OCC92<=203
replace SE92_class=9 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=212 & SE_OCC92<=222
replace SE92_class=9 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==232
replace SE92_class=9 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==261
replace SE92_class=9 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==299
replace SE92_class=9 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==311
replace SE92_class=9 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==404

* Lower-grade managers and administrators (10)
replace SE92_class=10 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==211
replace SE92_class=10 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==293
replace SE92_class=10 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==294
replace SE92_class=10 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==297
replace SE92_class=10 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==312
replace SE92_class=10 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==313
replace SE92_class=10 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==321
replace SE92_class=10 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==332

****NB: no good differenciation possible between (9) and (10) fpr manager of "small" entreprises

* Skilled clerks (11)
replace SE92_class=11 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==241
replace SE92_class=11 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==242
replace SE92_class=11 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==249
replace SE92_class=11 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==291
replace SE92_class=11 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==292
replace SE92_class=11 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==295
replace SE92_class=11 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==296
replace SE92_class=11 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==671
replace SE92_class=11 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==673
replace SE92_class=11 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==681
replace SE92_class=11 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==904

* Unskilled clerks (12)
replace SE92_class=12 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==674

* Socio-cultural professionals (13)
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=30 & SE_OCC92<=32
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==34
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==35
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==37
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==41
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==61
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==103
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==104
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=106 & SE_OCC92<=121
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==131
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==153
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==155
replace SE92_class=13 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==191

* Socio-cultural semi-professionals (14)
replace SE92_class=14 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==33
replace SE92_class=14 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==36
replace SE92_class=14 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==39
replace SE92_class=14 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==49
replace SE92_class=14 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==71
replace SE92_class=14 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=76 & SE_OCC92<=79
replace SE92_class=14 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==151
replace SE92_class=14 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==159
replace SE92_class=14 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==169

* Skilled service (15)
replace SE92_class=15 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==123
replace SE92_class=15 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==139
replace SE92_class=15 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==333
replace SE92_class=15 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==339
replace SE92_class=15 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==640
replace SE92_class=15 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==642
replace SE92_class=15 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=901 & SE_OCC92<=903
replace SE92_class=15 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==911
replace SE92_class=15 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==941

* Low-skilled service (16)
replace SE92_class=16 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==154
replace SE92_class=16 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92==682
replace SE92_class=16 if (SELFEMP==2 | SELFEMP==.a) & SE_OCC92>=913 & SE_OCC92<=932

* Not classifiable (0): military + "other occupation"

replace SE92_class=0 if SE_OCC92==981
replace SE92_class=. if SE_OCC92==.i


tab SE92_class if COUNTRY==752 & YEAR==1992, m

*********************************************************
* Recode class16_r, class16_p, class8_r, class8_p, class5_r, class5_p
* Recode class16, class8, class5
* for Sweden 1992
*********************************************************

replace class16_r=SE92_class if COUNTRY==752 & YEAR==1992
replace class16_r=. if SE92_class==0 & COUNTRY==752 & YEAR==1992

recode class16_r (0=.)

replace class8_r=class16_r if COUNTRY==752 & YEAR==1992
recode class8_r (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8) if COUNTRY==752 & YEAR==1992

replace class5_r=class16_r if COUNTRY==752 & YEAR==1992
recode class5_r (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5) if COUNTRY==752 & YEAR==1992

replace class16=class16_r if COUNTRY==752 & YEAR==1992

replace class8=class16 if COUNTRY==752 & YEAR==1992
recode class8 (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8) if COUNTRY==752 & YEAR==1992

replace class5=class16 if COUNTRY==752 & YEAR==1992
recode class5 (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5) if COUNTRY==752 & YEAR==1992


*******************************************************************************
* SPECIFIC Oesch’s class schema for United States 1987
*******************************************************************************

*************************************************
* Create Oesch class schema for respondent
* Create US87_class
* Using US_OCC87 and SELFEMP
*************************************************

gen US87_class=.

* Large employers (1)
replace US87_class=1 if SELFEMP==1 & US_OCC87>=202 & US_OCC87<=224
replace US87_class=1 if SELFEMP==1 & US_OCC87>=231 & US_OCC87<=233

****NB: no good differenciation possible between (1) and (3)

* Self-employed professionals (2)
replace US87_class=2 if SELFEMP==1 & US_OCC87>=1 & US_OCC87<=65
replace US87_class=2 if SELFEMP==1 & US_OCC87>=91 & US_OCC87<=152
replace US87_class=2 if SELFEMP==1 & US_OCC87>=174 & US_OCC87<=201
replace US87_class=2 if SELFEMP==1 & US_OCC87>=240 & US_OCC87<=245

* Small business owners with employees (3)
replace US87_class=3 if SELFEMP==1 & US_OCC87==230
replace US87_class=3 if SELFEMP==1 & US_OCC87==801

* Small business owners without employees (4)
replace US87_class=4 if SELFEMP==1 & US_OCC87>=74 & US_OCC87<=90
replace US87_class=4 if SELFEMP==1 & US_OCC87>=153 & US_OCC87<=173
replace US87_class=4 if SELFEMP==1 & US_OCC87==225
replace US87_class=4 if SELFEMP==1 & US_OCC87>=260 & US_OCC87<=563
replace US87_class=4 if SELFEMP==1 & US_OCC87>=601 & US_OCC87<=785
replace US87_class=4 if SELFEMP==1 & US_OCC87>=822 & US_OCC87<=984

* Technical experts (5)
replace US87_class=5 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=1 & US_OCC87<=25

* Technicians (6)
replace US87_class=6 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=153 & US_OCC87<=173
replace US87_class=6 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==450
replace US87_class=6 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==452
replace US87_class=6 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==610

* Skilled manual (7)
replace US87_class=7 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=402 & US_OCC87<=446
replace US87_class=7 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=454 & US_OCC87<=563
replace US87_class=7 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=613 & US_OCC87<=620
replace US87_class=7 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==624
replace US87_class=7 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==645
replace US87_class=7 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==663
replace US87_class=7 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=671 & US_OCC87<=680
replace US87_class=7 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==740
replace US87_class=7 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==752
replace US87_class=7 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==755
replace US87_class=7 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==761
replace US87_class=7 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==763

* Low-skilled manual (8)
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=601 & US_OCC87<=612
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=622 & US_OCC87<=623
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=630 & US_OCC87<=643
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=650 & US_OCC87<=656
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==664
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=690 & US_OCC87<=695
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==706
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==715
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==751
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==753
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==760
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==762
replace US87_class=8 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=764 & US_OCC87<=823

* Higher-grade managers and administrators (9)
replace US87_class=9 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==30
replace US87_class=9 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==31
replace US87_class=9 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==91
replace US87_class=9 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=201 & US_OCC87<=224
replace US87_class=9 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=230 & US_OCC87<=233
replace US87_class=9 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==245


* Lower-grade managers and administrators (10)
replace US87_class=10 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==225
replace US87_class=10 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==240
replace US87_class=10 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=265 & US_OCC87<=271
replace US87_class=10 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==305
replace US87_class=10 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==964
replace US87_class=10 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==965

* Skilled clerks (11)
replace US87_class=11 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==301
replace US87_class=11 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=310 & US_OCC87<=314
replace US87_class=11 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=320 & US_OCC87<=381
replace US87_class=11 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=391 & US_OCC87<=395

* Unskilled clerks (12)
replace US87_class=12 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==315
replace US87_class=12 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=384 & US_OCC87<=390

* Socio-cultural professionals (13)
replace US87_class=13 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=32 & US_OCC87<=65
replace US87_class=13 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==93
replace US87_class=13 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=110 & US_OCC87<=141
replace US87_class=13 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=144 & US_OCC87<=152
replace US87_class=13 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==174
replace US87_class=13 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==181
replace US87_class=13 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==184

* Socio-cultural semi-professionals (14)
replace US87_class=14 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=74 & US_OCC87<=90
replace US87_class=14 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==100
replace US87_class=14 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==142
replace US87_class=14 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==143
replace US87_class=14 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==175
replace US87_class=14 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==183
replace US87_class=14 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=185 & US_OCC87<=195
replace US87_class=14 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==382
replace US87_class=14 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==922
replace US87_class=14 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==924

* Skilled service (15)
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==226
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==260
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==262
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==280
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==640
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==703
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==912
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==921
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=925 & US_OCC87<=933
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==935
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==942
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==944
replace US87_class=15 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=960 & US_OCC87<=962

* Low-skilled service (16)
replace US87_class=16 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==264
replace US87_class=16 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==705
replace US87_class=16 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==705
replace US87_class=16 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==714
replace US87_class=16  if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=901 & US_OCC87<=911
replace US87_class=16  if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=913 & US_OCC87<=916
replace US87_class=16 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==934
replace US87_class=16 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==940
replace US87_class=16 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==950
replace US87_class=16 if (SELFEMP==2 | SELFEMP==.a) & US_OCC87==952
replace US87_class=16  if (SELFEMP==2 | SELFEMP==.a) & US_OCC87>=980 & US_OCC87<=984

* Not classifiable (0): military + "other occupation"

replace US87_class=0 if US_OCC87==580
replace US87_class=0 if US_OCC87==590

replace US87_class=. if US_OCC87==.a
replace US87_class=. if US_OCC87==.c
replace US87_class=. if US_OCC87==.n


tab US87_class if COUNTRY==840 & YEAR==1987, m


*********************************************************
* Recode class16_r, class16_p, class8_r, class8_p, class5_r, class5_p
* Recode class16, class8, class5
* for United States 1987
*********************************************************

replace class16_r=US87_class if COUNTRY==840 & YEAR==1987

recode class16_r (0=.)



replace class8_r=class16_r if COUNTRY==840 & YEAR==1987
recode class8_r (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8) if COUNTRY==840 & YEAR==1987

replace class5_r=class16_r if COUNTRY==840 & YEAR==1987
recode class5_r (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5) if COUNTRY==840 & YEAR==1987

replace class16=class16_r if COUNTRY==840 & YEAR==1987

replace class8=class16 if COUNTRY==840 & YEAR==1987
recode class8 (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8) if COUNTRY==840 & YEAR==1987

replace class5=class16 if COUNTRY==840 & YEAR==1987
recode class5 (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5) if COUNTRY==840 & YEAR==1987


*******************************************************************************
* SPECIFIC Oesch’s class schema for Poland 1987
* NB: Only 5-Class schema can be created
* Recode class5
* Using PL_OCC87
*******************************************************************************

replace class5=1 if (PL_OCC87==1 | PL_OCC87==2) & COUNTRY==616 & YEAR==1987
replace class5=2 if (PL_OCC87==3) & COUNTRY==616 & YEAR==1987
replace class5=3 if (PL_OCC87==6 | PL_OCC87==11) & COUNTRY==616 & YEAR==1987 
replace class5=4 if (PL_OCC87==4 | PL_OCC87==5| PL_OCC87==7 |PL_OCC87==8) & COUNTRY==616 & YEAR==1987
replace class5=5 if (PL_OCC87==9 | PL_OCC87==10| PL_OCC87==12) & COUNTRY==616 & YEAR==1987


*******************************************************************************
* SPECIFIC Oesch’s class schema for ITALY 1987
* NB: Due to the lack of information, only 8-Class schema and 5-Class schema can be created
*******************************************************************************

*************************************************
* Create Oesch 8-Class schema for respondent
* Create IT87_class8
* Using IT_OCC87 and SELFEMP
*************************************************

gen IT87_class8=.

replace IT87_class8=1 if (IT_OCC87==11 | IT_OCC87==12 | IT_OCC87==14) & SELFEMP==1
replace IT87_class8=2 if (IT_OCC87==44 | IT_OCC87==43 | IT_OCC87==46) & SELFEMP==1
*NB1: no accurate distiction is possible between big business holder (IT87_class8=1) and small business holder (IT87_class8=2): all "Entrepreneurs, manufacturers" have been assigned to IT87_class8==1.
*NB2: No tecnical experts or tecnicians (IT87_class8=3) can be identified 

replace IT87_class8=4 if (IT_OCC87==31 | IT_OCC87==34 | IT_OCC87==43) & (SELFEMP==2 | SELFEMP==.)
replace IT87_class8=5 if (IT_OCC87==21 | IT_OCC87==24 | IT_OCC87==25 | IT_OCC87==42 | IT_OCC87==46) & (SELFEMP==2 | SELFEMP==.)
replace IT87_class8=6 if IT_OCC87==26 & (SELFEMP==2 | SELFEMP==.)
replace IT87_class8=7 if (IT_OCC87==13 | IT_OCC87==22 | IT_OCC87==23) & (SELFEMP==2 | SELFEMP==.)
replace IT87_class8=8 if (IT_OCC87==33 | IT_OCC87==41 | IT_OCC87==45) & (SELFEMP==2 | SELFEMP==.)
replace IT87_class8=. if IT_OCC87==32


*************************************************
* Create Oesch 5-Class schema for respondent
* Create IT87_class5
* Using IT_OCC87 and SELFEMP
*************************************************
gen IT87_class5=.

replace IT87_class5=1 if (IT_OCC87==11 | IT_OCC87==12 | IT_OCC87==14) & SELFEMP==1
*NB1: no accurate distiction is possible between big business holder (IT87_class5=1) and small business holder (IT87_class5=3): all "Entrepreneurs, manufacturers" have been assigned to IT87_class5==1.

replace IT87_class5=1 if (IT_OCC87==21 | IT_OCC87==22 | IT_OCC87==23) & (SELFEMP==2 | SELFEMP==.)

replace IT87_class5=2 if (IT_OCC87==13 | IT_OCC87==24 |IT_OCC87==25| IT_OCC87==26 | IT_OCC87==42 | IT_OCC87==46) & (SELFEMP==2 | SELFEMP==.)
*NB2: No tecnical experts (IT87_class5=1) or tecnicians (IT87_class5=2) can be identified accordig to the disposable categories in IT_OCC87

replace IT87_class5=3 if (IT_OCC87==43 | IT_OCC87==44 |IT_OCC87==46) & (SELFEMP==1)

replace IT87_class5=4 if (IT_OCC87==41) & (SELFEMP==2 | SELFEMP==.)
replace IT87_class5=5 if (IT_OCC87==31 | IT_OCC87==33| IT_OCC87==34 | IT_OCC87==45) & (SELFEMP==2 | SELFEMP==.)
*NB: no accurate distiction between skilled workers (IT87_class5=4) and unskilled  (IT87_class5=5) workers is possible: all "Workers, operatives or similar" has been assigned to IT87_class5=5.



*************************************************
*recode class8 and class5 for Italy 1987
*using IT87_class8, IT87_class5, IT87_pclass8 and IT87_pclass5
*************************************************
replace class8_r=IT87_class8 if COUNTRY==380 & YEAR==1987

replace class8=IT87_class8 if COUNTRY==380 & YEAR==1987

replace class5_r=IT87_class5 if COUNTRY==380 & YEAR==1987

replace class5=IT87_class5 if COUNTRY==380 & YEAR==1987



*******************************************************************************
* SPECIFIC Oesch’s class schema for ITALY 1992
* NB: Due to the lack of information, only 8-Class schema and 5-Class schema can be created
*******************************************************************************

*************************************************
* Create Oesch 8-Class schema for respondent
* Create IT92_class8
* Using IT_OCC92 and SELFEMP
*************************************************

gen IT92_class8=.

replace IT92_class8=1 if (IT_OCC92==1 | IT_OCC92==2 | IT_OCC92==4) & SELFEMP==1
replace IT92_class8=2 if (IT_OCC92==19 | IT_OCC92==18 | IT_OCC92==21) & SELFEMP==1
*NB1: no accurate distiction is possible between big business holder (IT92_class8=1) and small business holder (IT92_class8=2): all "Entrepreneurs, manufacturers" have been assigned to IT92_class8==1.
*NB2: No tecnical experts or tecnicians (IT92_class8=3) can be identified 

replace IT92_class8=4 if (IT_OCC92==12 | IT_OCC92==15 | IT_OCC92==18) & (SELFEMP==2 | SELFEMP==.)
replace IT92_class8=5 if (IT_OCC92==16 | IT_OCC92==8 | IT_OCC92==9 | IT_OCC92==17 | IT_OCC92==21) & (SELFEMP==2 | SELFEMP==.)
replace IT92_class8=6 if IT_OCC92==10 & (SELFEMP==2 | SELFEMP==.)
replace IT92_class8=7 if (IT_OCC92==3 | IT_OCC92==6 | IT_OCC92==7) & (SELFEMP==2 | SELFEMP==.)
replace IT92_class8=8 if (IT_OCC92==14 | IT_OCC92==16 | IT_OCC92==20 | IT_OCC92==22) & (SELFEMP==2 | SELFEMP==.)
replace IT92_class8=. if IT_OCC92==32


*************************************************
* Create Oesch 5-Class schema for respondent
* Create IT92_class5
* Using IT_OCC92 and SELFEMP
*************************************************
gen IT92_class5=.

replace IT92_class5=1 if (IT_OCC92==1 | IT_OCC92==2 | IT_OCC92==4) & SELFEMP==1
*NB1: no accurate distiction is possible between big business holder (IT92_class5=1) and small business holder (IT92_class5=3): all "Entrepreneurs, manufacturers" have been assigned to IT92_class5==1.

replace IT92_class5=1 if (IT_OCC92==5 | IT_OCC92==6 | IT_OCC92==7) & (SELFEMP==2 | SELFEMP==.)

replace IT92_class5=2 if (IT_OCC92==3 | IT_OCC92==8 |IT_OCC92==9| IT_OCC92==10 | IT_OCC92==17 | IT_OCC92==21) & (SELFEMP==2 | SELFEMP==.)
*NB2: No tecnical experts (IT92_class5=1) or tecnicians (IT92_class5=2) can be identified accordig to the disposable categories in IT_OCC92

replace IT92_class5=3 if (IT_OCC92==18 | IT_OCC92==19 |IT_OCC92==21) & (SELFEMP==1)

replace IT92_class5=4 if (IT_OCC92==16) & (SELFEMP==2 | SELFEMP==.)
replace IT92_class5=5 if (IT_OCC92==12 | IT_OCC92==13| IT_OCC92==15 | IT_OCC92==20) & (SELFEMP==2 | SELFEMP==.)
*NB: no accurate distiction between skilled workers (IT92_class5=4) and unskilled  (IT92_class5=5) workers is possible: all "Workers, operatives or similar" has been assigned to IT92_class5=5.



*************************************************
*recode class8 and class5 for Italy 1992
*using IT92_class8, IT92_class5, IT92_pclass8 and IT92_pclass5
*************************************************
replace class8_r=IT92_class8 if COUNTRY==380 & YEAR==1992

replace class8=IT92_class8 if COUNTRY==380 & YEAR==1992

replace class5_r=IT92_class5 if COUNTRY==380 & YEAR==1992

replace class5=IT92_class5 if COUNTRY==380 & YEAR==1992


save "$path\DATASET_1987-2013_classnopart.dta", replace





*******************************************************************************
* OESCH CLASS SCHEMA
* Create 16-Class schema, 8-Class schema and 5-Class schema
* Data: ISSP 2014-2017 (containing ISCO08 codes)
*******************************************************************************
use "$path\DATASET_1987-2018_classnopart.dta", clear

keep if YEAR>2013

save "$path\DATASET_2014-18_classnopart.dta", replace
use "$path\DATASET_2014-18_classnopart.dta", clear
*******************************************************************************
* Respondent's Oesch class position
* Recode and create variables used to construct class variable for respondents
* Variables used to construct class variable for respondents: ISCO08, EMPREL, NEMPLOY 
*******************************************************************************
 
**** Recode occupation variable (isco08 com-4-digit) for respondents

tab ISCO08, m
 
recode ISCO08 (missing=-9), copyrest gen(isco08_mainjob)
recode isco08_mainjob (0=-9)
label variable isco08_mainjob "Current occupation of respondent - isco08 4-digit"
tab isco08_mainjob


**** Recode employment status for respondents
 
recode NEMPLOY (1/9=1)(10/9990=2)(.=.) (.a=.) (.n=.) (9997=.) (9998=.) (9999=.), gen(emplno_r)
label define emplno_r ///
0 "0 employees" ///
1 "1-9 employees" ///
2 "10+ employees"
label value emplno_r emplno_r
tab emplno_r
									
gen selfemp_r=9
replace selfemp_r=1 if emplno_r==1 | emplno_r==2 | EMPREL==2 | EMPREL==3 | EMPREL==4
replace selfemp_r=2 if EMPREL==1
label define selfemp_r 1"Self-employed" 2 "Employee" 9 "Missing"
label value selfemp_r selfemp_r			
tab selfemp_r

gen selfem_mainjob=.
replace selfem_mainjob=1 if selfemp_r==2 | selfemp_r==9
replace selfem_mainjob=2 if (selfemp_r==1 & (emplno_r==0 | emplno_r==.)) | EMPREL==2 | EMPREL==4
replace selfem_mainjob=3 if (selfemp_r==1 | selfemp_r==9) & emplno_r==1 
replace selfem_mainjob=4 if (selfemp_r==1 | selfemp_r==9) & emplno_r==2
label variable selfem_mainjob "Employment status for respondants"
label define selfem_mainjob 1 "Not self-employed" 2 "Self-empl without employees" 3 "Self-empl with 1-9 employees" 4 "Self-empl with 10 or more" 
label value selfem_mainjob selfem_mainjob
tab selfem_mainjob, m
                                 
***NB1: selfem_mainjob=1 if selfemp_r==9 -> people we don't know if they are self-employed or not are considered to be employees
***NB2: selfem_mainjob=2 selfemp_r==1 & emplno_r==. -> self-employed people we don't know how many employees they have are considered to be self-employed without employees

*************************************************
* Create Oesch class schema for respondents
* Create class16_r class8_r class5_r
* Using isco08_mainjob and selfem_mainjob
*************************************************

gen class16_r = -9

* Large employers (1)

replace class16_r=1 if selfem_mainjob==4

* Self-employed professionals (2)

replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob >= 2000 & isco08_mainjob <= 2162) 
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob >= 2164 & isco08_mainjob <= 2165) 
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob >= 2200 & isco08_mainjob <= 2212) 
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob == 2250)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob >= 2261 & isco08_mainjob <= 2262)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob >= 2300 & isco08_mainjob <= 2330)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob >= 2350 & isco08_mainjob <= 2352)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob >= 2359 & isco08_mainjob <= 2432)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob >= 2500 & isco08_mainjob <= 2619)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob == 2621)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob >= 2630 & isco08_mainjob <= 2634)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob >= 2636 & isco08_mainjob <= 2640)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco08_mainjob >= 2642 & isco08_mainjob <= 2643)

* Small business owners with employees (3)

replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob >= 1000 & isco08_mainjob <= 1439)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob == 2163)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob == 2166)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob >= 2220 & isco08_mainjob <= 2240)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob == 2260)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob >= 2263 & isco08_mainjob <= 2269)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob >= 2340 & isco08_mainjob <= 2342)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob >= 2353 & isco08_mainjob <= 2356)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob >= 2433 & isco08_mainjob <= 2434)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob == 2620)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob == 2622)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob == 2635)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob == 2641)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob >= 2650 & isco08_mainjob <= 2659)
replace class16_r=3 if (selfem_mainjob==3) & (isco08_mainjob >= 3000 & isco08_mainjob <= 9629)

* Small business owners without employees (4)

replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob >= 1000 & isco08_mainjob <= 1439)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob == 2163)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob == 2166)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob >= 2220 & isco08_mainjob <= 2240)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob == 2260)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob >= 2263 & isco08_mainjob <= 2269)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob >= 2340 & isco08_mainjob <= 2342)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob >= 2353 & isco08_mainjob <= 2356)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob >= 2433 & isco08_mainjob <= 2434)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob == 2620)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob == 2622)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob == 2635)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob == 2641)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob >= 2650 & isco08_mainjob <= 2659)
replace class16_r=4 if (selfem_mainjob==2) & (isco08_mainjob >= 3000 & isco08_mainjob <= 9629)

* Technical experts (5)

replace class16_r=5 if (selfem_mainjob==1) & (isco08_mainjob >= 2100 & isco08_mainjob <= 2162)
replace class16_r=5 if (selfem_mainjob==1) & (isco08_mainjob >= 2164 & isco08_mainjob <= 2165)
replace class16_r=5 if (selfem_mainjob==1) & (isco08_mainjob >= 2500 & isco08_mainjob <= 2529)

* Technicians (6)

replace class16_r=6 if (selfem_mainjob==1) & (isco08_mainjob >= 3100 & isco08_mainjob <= 3155)
replace class16_r=6 if (selfem_mainjob==1) & (isco08_mainjob >= 3210 & isco08_mainjob <= 3214)
replace class16_r=6 if (selfem_mainjob==1) & (isco08_mainjob == 3252)
replace class16_r=6 if (selfem_mainjob==1) & (isco08_mainjob >= 3500 & isco08_mainjob <= 3522)

* Skilled manual (7)

replace class16_r=7 if (selfem_mainjob==1) & (isco08_mainjob >= 6000 & isco08_mainjob <= 7549)
replace class16_r=7 if (selfem_mainjob==1) & (isco08_mainjob >= 8310 & isco08_mainjob <= 8312)
replace class16_r=7 if (selfem_mainjob==1) & (isco08_mainjob == 8330)
replace class16_r=7 if (selfem_mainjob==1) & (isco08_mainjob >= 8332 & isco08_mainjob <= 8340)
replace class16_r=7 if (selfem_mainjob==1) & (isco08_mainjob >= 8342 & isco08_mainjob <= 8344)

* Low-skilled manual (8)

replace class16_r=8 if (selfem_mainjob==1) & (isco08_mainjob >= 8000 & isco08_mainjob <= 8300)
replace class16_r=8 if (selfem_mainjob==1) & (isco08_mainjob >= 8320 & isco08_mainjob <= 8321)
replace class16_r=8 if (selfem_mainjob==1) & (isco08_mainjob == 8341)
replace class16_r=8 if (selfem_mainjob==1) & (isco08_mainjob == 8350)
replace class16_r=8 if (selfem_mainjob==1) & (isco08_mainjob >= 9200 & isco08_mainjob <= 9334)
replace class16_r=8 if (selfem_mainjob==1) & (isco08_mainjob >= 9600 & isco08_mainjob <= 9620)
replace class16_r=8 if (selfem_mainjob==1) & (isco08_mainjob >= 9622 & isco08_mainjob <= 9629)

* Higher-grade managers and administrators (9)

replace class16_r=9 if (selfem_mainjob==1) & (isco08_mainjob >= 1000 & isco08_mainjob <= 1300)
replace class16_r=9 if (selfem_mainjob==1) & (isco08_mainjob >= 1320 & isco08_mainjob <= 1349)
replace class16_r=9 if (selfem_mainjob==1) & (isco08_mainjob >= 2400 & isco08_mainjob <= 2432)
replace class16_r=9 if (selfem_mainjob==1) & (isco08_mainjob >= 2610 & isco08_mainjob <= 2619)
replace class16_r=9 if (selfem_mainjob==1) & (isco08_mainjob == 2631)
replace class16_r=9 if (selfem_mainjob==1) & (isco08_mainjob >= 100 & isco08_mainjob <= 110)

* Lower-grade managers and administrators (10)

replace class16_r=10 if (selfem_mainjob==1) & (isco08_mainjob >= 1310 & isco08_mainjob <= 1312)
replace class16_r=10 if (selfem_mainjob==1) & (isco08_mainjob >= 1400 & isco08_mainjob <= 1439)
replace class16_r=10 if (selfem_mainjob==1) & (isco08_mainjob >= 2433 & isco08_mainjob <= 2434)
replace class16_r=10 if (selfem_mainjob==1) & (isco08_mainjob >= 3300 & isco08_mainjob <= 3339)
replace class16_r=10 if (selfem_mainjob==1) & (isco08_mainjob == 3343)
replace class16_r=10 if (selfem_mainjob==1) & (isco08_mainjob >= 3350 & isco08_mainjob <= 3359)
replace class16_r=10 if (selfem_mainjob==1) & (isco08_mainjob == 3411)
replace class16_r=10 if (selfem_mainjob==1) & (isco08_mainjob == 5221)
replace class16_r=10 if (selfem_mainjob==1) & (isco08_mainjob >= 200 & isco08_mainjob <= 210)

* Skilled clerks (11)

replace class16_r=11 if (selfem_mainjob==1) & (isco08_mainjob >= 3340 & isco08_mainjob <= 3342)
replace class16_r=11 if (selfem_mainjob==1) & (isco08_mainjob == 3344)
replace class16_r=11 if (selfem_mainjob==1) & (isco08_mainjob >= 4000 & isco08_mainjob <= 4131)
replace class16_r=11 if (selfem_mainjob==1) & (isco08_mainjob >= 4200 & isco08_mainjob <= 4221)
replace class16_r=11 if (selfem_mainjob==1) & (isco08_mainjob >= 4224 & isco08_mainjob <= 4413)
replace class16_r=11 if (selfem_mainjob==1) & (isco08_mainjob >= 4415 & isco08_mainjob <= 4419)

* Unskilled clerks (12)

replace class16_r=12 if (selfem_mainjob==1) & (isco08_mainjob == 4132)
replace class16_r=12 if (selfem_mainjob==1) & (isco08_mainjob == 4222)
replace class16_r=12 if (selfem_mainjob==1) & (isco08_mainjob == 4223)
replace class16_r=12 if (selfem_mainjob==1) & (isco08_mainjob == 5230)
replace class16_r=12 if (selfem_mainjob==1) & (isco08_mainjob == 9621)

* Socio-cultural professionals (13)

replace class16_r=13 if (selfem_mainjob==1) & (isco08_mainjob >= 2200 &  isco08_mainjob <= 2212)
replace class16_r=13 if (selfem_mainjob==1) & (isco08_mainjob == 2250)
replace class16_r=13 if (selfem_mainjob==1) & (isco08_mainjob >= 2261 &  isco08_mainjob <= 2262)
replace class16_r=13 if (selfem_mainjob==1) & (isco08_mainjob >= 2300 &  isco08_mainjob <= 2330)
replace class16_r=13 if (selfem_mainjob==1) & (isco08_mainjob >= 2350 &  isco08_mainjob <= 2352)
replace class16_r=13 if (selfem_mainjob==1) & (isco08_mainjob == 2359)
replace class16_r=13 if (selfem_mainjob==1) & (isco08_mainjob == 2600)
replace class16_r=13 if (selfem_mainjob==1) & (isco08_mainjob == 2621)
replace class16_r=13 if (selfem_mainjob==1) & (isco08_mainjob == 2630)
replace class16_r=13 if (selfem_mainjob==1) & (isco08_mainjob >= 2632 &  isco08_mainjob <= 2634)
replace class16_r=13 if (selfem_mainjob==1) & (isco08_mainjob >= 2636 &  isco08_mainjob <= 2640)
replace class16_r=13 if (selfem_mainjob==1) & (isco08_mainjob >= 2642 &  isco08_mainjob <= 2643)

* Socio-cultural semi-professionals (14)

replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob == 2163)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob == 2166)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob >= 2220 & isco08_mainjob <= 2240)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob == 2260)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob >= 2263 & isco08_mainjob <= 2269)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob >= 2340 & isco08_mainjob <= 2342)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob >= 2353 & isco08_mainjob <= 2356)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob == 2620)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob == 2622)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob == 2635)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob == 2641)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob >= 2650 & isco08_mainjob <= 2659)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob == 3200)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob >= 3220 & isco08_mainjob <= 3230)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob == 3250)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob >= 3253 & isco08_mainjob <= 3257)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob == 3259)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob >= 3400 & isco08_mainjob <= 3410)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob >= 3412 & isco08_mainjob <= 3413)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob >= 3430 & isco08_mainjob <= 3433)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob == 3435)
replace class16_r=14 if (selfem_mainjob==1) & (isco08_mainjob == 4414)

* Skilled service (15)

replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob == 3240)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob == 3251)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob == 3258)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob >= 3420 & isco08_mainjob <= 3423)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob == 3434)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob >= 5000 & isco08_mainjob <= 5120)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob >= 5140 & isco08_mainjob <= 5142)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob == 5163)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob == 5165)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob == 5200)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob == 5220)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob >= 5222 & isco08_mainjob <= 5223)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob >= 5241 & isco08_mainjob <= 5242)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob >= 5300 & isco08_mainjob <= 5321)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob >= 5400 & isco08_mainjob <= 5413)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob == 5419)
replace class16_r=15 if (selfem_mainjob==1) & (isco08_mainjob == 8331)

* Low-skilled service (16)

replace class16_r=16 if (selfem_mainjob==1) & (isco08_mainjob >= 5130 & isco08_mainjob <= 5132)
replace class16_r=16 if (selfem_mainjob==1) & (isco08_mainjob >= 5150 & isco08_mainjob <= 5162)
replace class16_r=16 if (selfem_mainjob==1) & (isco08_mainjob == 5164)
replace class16_r=16 if (selfem_mainjob==1) & (isco08_mainjob == 5169)
replace class16_r=16 if (selfem_mainjob==1) & (isco08_mainjob >= 5210 & isco08_mainjob <= 5212)
replace class16_r=16 if (selfem_mainjob==1) & (isco08_mainjob == 5240)
replace class16_r=16 if (selfem_mainjob==1) & (isco08_mainjob >= 5243 & isco08_mainjob <= 5249)
replace class16_r=16 if (selfem_mainjob==1) & (isco08_mainjob >= 5322 & isco08_mainjob <= 5329)
replace class16_r=16 if (selfem_mainjob==1) & (isco08_mainjob == 5414)
replace class16_r=16 if (selfem_mainjob==1) & (isco08_mainjob == 8322)
replace class16_r=16 if (selfem_mainjob==1) & (isco08_mainjob >= 9100 & isco08_mainjob <= 9129)
replace class16_r=16 if (selfem_mainjob==1) & (isco08_mainjob >= 9400 & isco08_mainjob <= 9520)


***NB: a missing value in class16_r when isco08_mainjob!=. means that the value of selfem_mainjob was not coherent with the job type


mvdecode class16_r, mv(-9)
label variable class16_r "Respondent's Oesch class position - 16 classes"
label define class16_r ///
1 "Large employers" ///
2 "Self-employed professionals" ///
3 "Small business owners with employees" ///
4 "Small business owners without employees" ///
5 "Technical experts" ///
6 "Technicians" ///
7 "Skilled manual" ///
8 "Low-skilled manual" ///
9 "Higher-grade managers and administrators" ///
10 "Lower-grade managers and administrators" ///
11 "Skilled clerks" ///
12 "Unskilled clerks" ///
13 "Socio-cultural professionals" ///
14 "Socio-cultural semi-professionals" ///
15 "Skilled service" ///
16 "Low-skilled service"
label value class16_r class16_r
tab class16_r
 
recode class16_r (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8), gen(class8_r)
label variable class8_r "Respondent's Oesch class position - 8 classes"
label define class8_r ///
1 "Self-employed professionals and large employers" ///
2 "Small business owners" ///
3 "Technical (semi-)professionals" ///
4 "Production workers" ///
5 "(Associate) managers" ///
6 "Clerks" ///
7 "Socio-cultural (semi-)professionals" ///
8 "Service workers"
label value class8_r class8_r
tab class8_r

recode class16_r (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5), gen(class5_r)
label variable class5_r "Respondent's Oesch class position - 5 classes"
label define  class5_r ///
1 "Higher-grade service class" ///
2 "Lower-grade service class" ///
3 "Small business owners" ///
4 "Skilled workers" ///
5 "Unskilled workers"
label value class5_r class5_r
tab class5_r


****************************************************************************************************
 * Final Oesch class position
 ****************************************************************************************************

gen class16=class16_r

label variable class16 "Final Oesch class position - 16 classes"
label define class16 ///
1 "Large employers" ///
2 "Self-employed professionals" ///
3 "Small business owners with employees" ///
4 "Small business owners without employees" ///
5 "Technical experts" ///
6 "Technicians" ///
7 "Skilled manual" ///
8 "Low-skilled manual" ///
9 "Higher-grade managers and administrators" ///
10 "Lower-grade managers and administrators" ///
11 "Skilled clerks" ///
12 "Unskilled clerks" ///
13 "Socio-cultural professionals" ///
14 "Socio-cultural semi-professionals" ///
15 "Skilled service" ///
16 "Low-skilled service"
label value class16 class16
tab class16

recode class16 (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8), gen(class8)
label variable class8 "Final Oesch class position - 8 classes"
label define class8 ///
1 "Self-employed professionals and large employers" ///
2 "Small business owners" ///
3 "Technical (semi-)professionals" ///
4 "Production workers" ///
5 "(Associate) managers" ///
6 "Clerks" ///
7 "Socio-cultural (semi-)professionals" ///
8 "Service workers"
label value class8 class8
tab class8

recode class16 (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5), gen(class5)
label variable class5 "Final Oesch class position - 5 classes"
label define class5 ///
1 "Higher-grade service class" ///
2 "Lower-grade service class" ///
3 "Small business owners" ///
4 "Skilled workers" ///
5 "Unskilled workers"
label value class5 class5
tab class5


drop isco08_mainjob emplno_r selfem_mainjob

save "$path\DATASET_2014-18_classnopart.dta", replace


use "$path\DATASET_1987-2013_classnopart.dta", clear
append using "$path\DATASET_2014-18_classnopart.dta"
 
save "$path\DATASET_1987-2018_classnopart.dta", replace

*********CLASS SCHEMA with 6 classes: less hierarchical***********

recode class16 (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(11 12=4)(7 8=5)(15 16=6), gen(class6)
label variable class6 "Final Oesch class position - 6 classes"
label define class6 ///
1 "Upper & upper-middle class" ///
2 "Lower middle class" ///
3 "Small business owners" ///
4 "Clerks"  ///
5 "Production workers" ///
6 "Service workers"
label value class6 class6
fre class6


save "$path\DATASET_1987-2018_classnopart.dta", replace

********************************************************************************
*drop repeated samples and attribute the years corresponding to data collection
********************************************************************************

*SWITWERLAND
drop if country=="CH" & (YEAR==2004 | YEAR==2006 | YEAR==2008 | YEAR==2010 | YEAR==2012 | YEAR==2014 | YEAR==2016)

*POLAND
drop if country=="PL" & (YEAR==2003 | YEAR==2006 | YEAR==2008 | YEAR==2011 | YEAR==2014)
rename YEAR year_original
gen YEAR_RECODED=year_original
recode YEAR (2004=2005) (2007=2008) (2009=2010) (2012=2013) if country=="PL"

*US
drop if country=="US" &  (YEAR==2003| YEAR==2005)
recode YEAR (2009=2010) (2013=2014) (2015=2016) (2017=2018) if country=="US"

*GERMANY
recode YEAR (2003=2004) (2005=2006) (2007=2008) (2009=2010) (2011=2012) (2013=2014) (2015=2016) (2017=2018) if country=="DE"

*AUSTRALIA
recode YEAR (2004=2005) (2008=2009) (2010=2012) (2011=2012) (2012=2013) if COUNTRY==36

*AUSTRIA
drop if COUNTRY==40 &  (YEAR==2003| YEAR==2007 | YEAR==2009)
recode YEAR (2012=2013) (2014=2015) (2017=2018) if COUNTRY==40

*SLOVENIA
drop if COUNTRY==705 & (YEAR==2008| YEAR==2010 | YEAR==2015)
recode YEAR (2002=2003) (2014=2013) if COUNTRY==705

*CZECH REPUBLIC
drop if COUNTRY==203 & (YEAR==2011)

*SLOVAKIAN REPUBLIC
drop if COUNTRY==703 & (YEAR==2007| YEAR==2010 | YEAR==2011)
recode YEAR (2004=2005)(2003=2004)  if COUNTRY==703

save "$path\DATASET_1987-2018_classnopart_ready.dta", replace



********************************************************************************
*erase intermediate datasets
********************************************************************************

erase "$path\DATASET_1987-2018_classnopart.dta"
erase "$path\DATASET_1987-2018.dta"
erase "$path\DATASET_1987-2013_class.dta"
erase "$path\DATASET_2014-18_class.dta"
erase "$path\DATASET_1987-2013_classnopart.dta"
erase "$path\DATASET_2014-18_classnopart.dta"
erase "$path\DATASET_2002_1.dta"
erase "$path\DATASET_2003_1.dta"
erase "$path\DATASET_2004_1.dta"
erase "$path\DATASET_2005_1.dta"
erase "$path\DATASET_2006_1.dta"
erase "$path\DATASET_2007_1.dta"
erase "$path\DATASET_2008_1.dta"
erase "$path\DATASET_2010_1.dta"
erase "$path\DATASET_2011_1.dta"
erase "$path\DATASET_2012_1.dta"
erase "$path\DATASET_2013_1.dta"
erase "$path\DATASET_2014_1.dta"
erase "$path\DATASET_2015_1.dta"
erase "$path\DATASET_2016_1.dta"
erase "$path\DATASET_2017_1.dta"
erase "$path\DATASET_addon1987-2009.dta"
erase "$path\DATASET_inequalities1987-2009.dta"
erase "$path\DATASET_inequalities1987-2009_1.dta"



********************************************************************************
*final datasets for analyses:
*DATASET_1987-2018_ready.dta
*DATASET_1987-2018_classnopart_ready.dta
********************************************************************************
